MATLAB: How to prevent axes clipping when changing zoom on a tall image

Image Processing ToolboxMATLAB

How do I prevent axes clipping when changing zoom on a tall image?
When I have a tall skinny image, it renders at proper aspect ratio, but when I zoom, the image is restricted to the initial viewport size. How can I allow zoom to preserve aspect ratio without clipping the width of my tall image?

Best Answer

There are two possible solutions to this issue, one using Image Processing Toolbox and one with base MATLAB.
Image Processing Toolbox - Image Viewer app:
The Image Viewer app (which can be opened via the "imtool" function) that comes with the Image Processing Toolbox has the desired zooming behavior. It can be used as follows:
im = imread('TallSkinny.png'); % Plots your image
imtool(im);
When zooming, the width of the tall image will expand to fill the figure. Here is a link to the documentation about "imtool" and the Image Viewer app:
Base MATLAB - No Axes Clipping:
In base MATLAB, you can change the Axes properties for "DataAspectRatioMode" and "Clipping" to achieve the desired behavior:
I = imread('TallSkinny.png');
imshow(I)
ax = gca;
ax.DataAspectRatioMode = 'manual';
ax.Clipping = 'off';
This should yield similar zooming behavior as does the "imtool" solution. Here is a link to the documentation about Axes properties: