How do I prevent axes clipping when changing zoom on a tall image?

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?

 Accepted 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.
Run this command in MATLAB 2016a for documentation about "imtool" and the Image Viewer app:
>> web(fullfile(docroot, 'images/ref/imtool.html'))
Or,
for latest release documentation about "imtool" and the Image Viewer app please refer to:
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.
Run this command in MATLAB 2016a for documentation about Axes properties:
>> web(fullfile(docroot, 'matlab/ref/axes-properties.html'))
Or,
for latest release documentation about Axes properties refer to:

More Answers (0)

Products

Release

R2016b

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!