How to change width and height of image?

2 ビュー (過去 30 日間)
andrew_cup
andrew_cup 2012 年 11 月 20 日
Hey, I'm trying to reduce the size of the height and width of an image only if the image width or height is over 400 pixels. Anybody know how I can do that? Here's the code:
im = imread('harry.jpg');
info = imfinfo('harry.jpg');
hoyde = info.Height;
bredde = info.Width;
if hoyde > 400 bredde > 400
nyhoyde = hoyde/2;
nybredde = bredde/2;
[nyhoyde,nybredde,kanaler] = size(im);
end

採用された回答

Image Analyst
Image Analyst 2012 年 11 月 20 日
Not sure I understand the language you used, but I'd do it like this:
reductionFactor = 0.5; % whatever...
[rows columns numberOfColorChannels] = size(im);
if rows>400 || columns > 400
im = imresize(im, reductionFactor);
end
  1 件のコメント
andrew_cup
andrew_cup 2012 年 11 月 20 日
Thank you! :-)

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

その他の回答 (1 件)

Thomas
Thomas 2012 年 11 月 20 日
編集済み: Thomas 2012 年 11 月 20 日
im = imread('harry.jpg');
info = imfinfo('harry.jpg');
hoyde = info.Height;
bredde = info.Width;
if hoyde > 400 || bredde > 400 %if rows or columns have more than 400px
iq=imresize(im,0.5); % reduce by factor 1/2=0.5
end
figure
imshow(im) % actual image
figure
imshow(iq) % reduced image

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by