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.
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()?
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.
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.
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.
0 Comments