Resize image without change aspect ratio of that image

3 ビュー (過去 30 日間)
Malan Jayanka
Malan Jayanka 2016 年 7 月 3 日
コメント済み: Malan Jayanka 2016 年 7 月 3 日
I have leaf image which got by scan real leaf. I want to reduce the dimensions of that image without change aspect ratio of the image. And it is not necessary to fit to given dimension. It can be used padding also. Simply I want to reduce image size to 256*256 and doesn't change aspect ratio of it. how to do this?

採用された回答

Walter Roberson
Walter Roberson 2016 年 7 月 3 日
%figure out the pad value to pad to white
if isinteger(YourImage)
pad = intmax(class(YourImage));
else
pad = 1; %white for floating point is 1.0
end
%figure out which dimension is longer and rescale that to be the 256
%and pad the shorter one to 256
[r, c, ~] = size(YourImage)
if r > c
newImage = imresize(YourImage, 256 / r);
NewImage(:, end+1 : 256, :) = pad;
elseif c > r
newImage = imresize(YourImage, 256 / c);
NewImage(end+1 : 256, :, :) = pad;
else
newImage = imresize(YourImage, [256, 256]);
end
  2 件のコメント
Image Analyst
Image Analyst 2016 年 7 月 3 日
There is also a padarray() function that can be used.
Malan Jayanka
Malan Jayanka 2016 年 7 月 3 日
Thank you sir, I will try this and if there are any problems I will ask from you sir

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by