MATLAB: How can you resize the image without deforming the image

cropimageImage Processing Toolboxreshaperesize

Can you please provide a code to resize an image without making it look different. Example I have a 2000 x 1500 pixel image size. I want the image to fit in an 1024 x 1024 size without reshaping it.

Best Answer

Try this:
% Prepare an input image for demo.
grayImage = imread('moon.tif');
grayImage = imresize(grayImage, [2000, 1500]);
subplot(1, 2, 1);
imshow(grayImage);
axis on;
% Now start....
% Resize gray image.
[rows, columns, numberOfColorChannels] = size(grayImage)
grayImage = imresize(grayImage, 1024/rows);
[rows, columns, numberOfColorChannels] = size(grayImage)
% Prepare side panels
sidePanelCols = (1024 - columns)/2
sidePanel = 200 * ones(rows, sidePanelCols, 'uint8');
% Construct new image
newImage = [sidePanel, grayImage, sidePanel];
subplot(1, 2, 2);
imshow(newImage);
axis on;
% axis equal