How do I prevent axes clipping when changing zoom on a tall image?
14 views (last 30 days)
Show older comments
MathWorks Support Team
on 16 Jan 2017
Edited: MathWorks Support Team
on 12 Apr 2023
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
MathWorks Support Team
on 12 Apr 2023
Edited: MathWorks Support Team
on 12 Apr 2023
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:
0 Comments
More Answers (0)
See Also
Categories
Find more on Explore and Edit Images with Image Viewer App in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!