MATLAB: Function to decrease image size

image processingImage Processing Toolboximresizeresize image

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 64×64 (the i parameter is the image)
This function doesnt work bc if scale is >1 it increases the image..

Best Answer

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
Related Question