フィルターのクリア

zoom image interactively maintaining a square zoom field

12 ビュー (過去 30 日間)
Duncan Carlsmith
Duncan Carlsmith 2023 年 4 月 10 日
コメント済み: Walter Roberson 2023 年 4 月 12 日
I'd like to use the + button with e.g. some control key, or some other trick, in order to zoom interactively on an image while maintaining a square 1:1 aspect ratio so the zoomed image is not distorted. Is there a way to do this?
  4 件のコメント
Walter Roberson
Walter Roberson 2023 年 4 月 10 日
You can use the PostAction callback to set the zoom limits back to what would fit with square aspect ratio.
Or you could turn on zoom for the x axis, and use the PostAction callback to make the same change to the y limits.
Duncan Carlsmith
Duncan Carlsmith 2023 年 4 月 10 日
Walter, OMG! I had no idea one could customize in this way - https://www.mathworks.com/help/matlab/creating_plots/create-callbacks-for-graphics-objects.html . That's awesome, have to try it out! Can you (cough cough) supply the code to do what I want? :)

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2023 年 4 月 10 日
Try using a scroll panel. See attached demo.
  1 件のコメント
Duncan Carlsmith
Duncan Carlsmith 2023 年 4 月 12 日
I wasn't familiar with Image Viewer app (https://www.mathworks.com/help/images/interact-with-images-using-image-viewer-app.html) which works like a charm for me in interactively scanning a square magnification field. I love dragging the view window around in the navigation view pane. Very cool demo you have there showing how one can roll one's own. Thank you!
This solution is suboptimal when I am viewing an image or plot just created in the Live Editor - I would have to open the plot in an external window, save the image, open the Image Viewer App, open the file... That use case is where I'd like a constrained Zoom mactive even in the Live Editor.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 4 月 10 日
ax = gca;
hZoom = zoom(ax);
setAxesZoomConstraint(hZoom, 'x');
hZoom.ActionPostCallback = {@SquareZoom, ax.XLim(1), ax.YLim(1)};
function SquareZoom(hObj, evd, x0, y0)
ax = evd.Axes;
xwid = diff(ax.XLim);
ax.XLim = [x0, x0 + xwid];
ax.YLim = [y0, y0 + xwid];
end
This particular implementation anchors the x and y on the lower left corner of the axes limits as they exist at the time the action is started. Every time the callback is invoked, the limits will be re-anchored at that position.
There are, of course, other valid interpretations on what to do; for example you might have valid reason to want to support panning as well. Or at initialization time you might want to find the shorter of the current x and y and clamp the limits according to the shorter to keep the desired 1:1 ratio.
  4 件のコメント
Duncan Carlsmith
Duncan Carlsmith 2023 年 4 月 12 日
I tried and the 10 April suggestion failed. I can't find documentation on the setAxisZoomConstraint function but https://stackoverflow.com/questions/65901058/setting-one-instance-of-a-graph-to-zoom-in-the-x-direction-only suggested I try this mod, which failed.
setAxesZoomConstraint(hZoom,ax, 'xy');
hZoom.ActionPostCallback = {@SquareZoom, ax.XLim(1), ax.YLim(1)};
It runs but still does not constrain to square.
The best thing would be... You know how if you control click a fig, you get to choose uncontrained, x, or y zoom. Best if constrained were an option there.
Walter Roberson
Walter Roberson 2023 年 4 月 12 日
setAxesZoomConstraint is listed under "object functions" in https://www.mathworks.com/help/matlab/ref/matlab.graphics.interaction.internal.zoom.html

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by