function to decrease image size

27 ビュー (過去 30 日間)
Altina Rexha
Altina Rexha 2020 年 9 月 28 日
コメント済み: Altina Rexha 2020 年 9 月 28 日
function [y] = ImageDecrease(i,n)
y=imresize(i,n);
size(y)
end
I need to create a function to decrease the image size. Ex. image size is 512px x 512px and if n=4 the size of image has to be 64x64 (the i parameter is the image)
This function doesnt work bc if scale is >1 it increases the image..

採用された回答

Image Analyst
Image Analyst 2020 年 9 月 28 日
I know it sounds obvious, so you've probably already done it by now, but did you try inverting the number:
function outputImage = ImageDecrease(inputImage, n)
[rows, columns, numberOfColorChannels] = size(inputImage);
fprintf('Input image has %d rows, %d columns, and %d color channels',rows, columns, numberOfColorChannels)
outputImage = imresize(inputImage, 1/n);
[rows, columns, numberOfColorChannels] = size(outputImage);
fprintf('Output image has %d rows, %d columns, and %d color channels',rows, columns, numberOfColorChannels)
end
  3 件のコメント
Image Analyst
Image Analyst 2020 年 9 月 28 日
It DOES work. And using imresize is not a bad idea.
rgbImage = imread('Peppers.png');
subplot(2, 1, 1);
imshow(rgbImage);
axis('on', 'image');
outputImage = ImageDecrease(rgbImage, 4);
subplot(2, 1, 2);
imshow(outputImage);
axis('on', 'image');
function outputImage = ImageDecrease(inputImage, n)
[rows, columns, numberOfColorChannels] = size(inputImage);
fprintf('Input image has %d rows, %d columns, and %d color channels',rows, columns, numberOfColorChannels)
outputImage = imresize(inputImage, 1/n);
[rows, columns, numberOfColorChannels] = size(outputImage);
fprintf('Output image has %d rows, %d columns, and %d color channels',rows, columns, numberOfColorChannels)
end
Note on the axes how the number of colums goes from 512 to 128, indicating a reduction by a factor of 4.
You can also pass in the exact number of rows and columns you want, if you prefer that way.
outputImage = imresize(inputImage, [123, 456]); % Make 123 rows by 456 columns.
Altina Rexha
Altina Rexha 2020 年 9 月 28 日
THank you it helped!!!

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

その他の回答 (0 件)

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by