Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How can I rescale an image while not changing the dimension of the image?

Asked by Richard Gueler on 21 Dec 2012

How can I rescale an image while not changing the dimension of the image? When I scale it up, it just crops the image to fit within the original size. When I scale it down, it pads the edges of the image with zeros. I want to zoom in and out about the center of the image. When using "imresize", it changes the dimensions of the image to preserve all the content. I have the image processing toolbox.

0 Comments

Richard Gueler

2 Answers

Answer by Image Analyst on 21 Dec 2012
Edited by Image Analyst on 21 Dec 2012

I'm not sure what you're talking about. How are you performing the scaling? Are you using the zoom() function? Are you using 'InitialMagnification' property of imshow()?

6 Comments

Walter Roberson on 21 Dec 2012

imresize() does output the processed image ?

Image Analyst on 21 Dec 2012

Like Walter says, imresize() does output a processed (i.e. resized) image. You can then cast that to a different bit depth, if you want. Look:

smallImage = imread('pout.tif');
whos smallImage
% Enlarge the image to 4000 by 6000, bigger than the monitor.
bigImage = uint16(imresize(smallImage, [4000,6000]));
whos bigImage
    Name              Size             Bytes  Class    Attributes
    smallImage      291x240            69840  uint8 
    Name             Size                 Bytes  Class     Attributes
    bigImage      4000x6000            48000000  uint16  

No zooming or displaying was done at all. Please tell us why this does not meet your needs.

Image Analyst on 22 Dec 2012

Richard - are you still there?????

Image Analyst
Answer by Jurgen on 21 Dec 2012
Edited by Jurgen on 21 Dec 2012

I think you want to look into imtransform, specifically the Xdata and Ydata properties. E.g. you can rotate around the center--keeping original size. Or rotate around the left corner (image moves out of view if you keep original dataspace). Etcetera for other 'focus' points and transform types.

2 Comments

Image Analyst on 21 Dec 2012

imrotate() can also crop or enlarge the canvass when you rotate. But he didn't say anything about rotation, just scaling. I'm still trying to figure out what he wants though.

Jurgen on 23 Dec 2012

e.g. means for example, or exempli gratia according to wiki--since we all know what is meant by rotate. Based on his wording, richard may not differentiate properly between scaling and cropping, so I chose rotate as example; imtransform can resize and crop too.

I think what he means is what some photo-viewing applications do when you scroll: the display window size remains constant and the image is scaled and cropped(or padded) around the center to the windowsize.

Should also be possible with imresize, but after the resize the user would need to manually crop or padd, e.g. using padarray or imcrop.

Jurgen

Contact us