MATLAB Answers

Sonoma Rich

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

Asked by Sonoma Rich
on 21 Dec 2012
Latest activity Commented on by YEIMY LISETH QUINTANA VILLAMIZAR on 23 Oct 2016 at 4:41

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.


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()?


Help me, please

I extract the object using click in the image, but is very small and I don't like, for this I need crop the image or make zoom, I attached the image input and image output that I need.

Image Analyst
on 23 Oct 2016 at 3:50

I don't understand. Simply use imcrop(). What's the difficulty?

yes, it's so easy, I'm a stupid.

Thaks so much.

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.


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.

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.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!