How could I make a callback that updates when the user moves an roi?

18 ビュー (過去 30 日間)
Turlough Hughes
Turlough Hughes 2020 年 2 月 15 日
回答済み: Turlough Hughes 2022 年 1 月 6 日
I'm making an app which loads and displays the same image side by side in app.UIAxes and app.UIAxes2. I have a rectangle roi object in app.UIAxes2 which the user can move around and adjust the size of. I want to take the coordiantes of the roi in app.UIAxes2 and use that to interactively zoom to those coordinates for the other UIAxes by changing the XLim and YLim accordingly. My issue is I don't know how to setup the callback so that it responds to a change in the position.
My question is really, is it possible to setup a value changing funtion that is called everytime the position values change in the roi, and if so how would I go about it? This would be similar to a value changing callback for a slider but the difference/issue being that draw rectangle is not part of the component library for app designer.
Any help/guidance would be appreciated.
  1 件のコメント
Arthur Roué
Arthur Roué 2020 年 3 月 11 日
I'm not familiar with ROI rectangle, but you could try to add a listener on it's DrawingArea property.
addlistener(roi, 'DrawingArea', 'PostSet', @foo)

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

採用された回答

Turlough Hughes
Turlough Hughes 2022 年 1 月 6 日
This is what I had in mind:
interactiveZoomDemo;
function [] = interactiveZoomDemo()
I = imread('saturn.png');
hf = figure();
subplot(1,2,1)
imshow(I)
% Reference
roiPosition = [120 180 400 450];
roi = drawrectangle('Position', roiPosition);
addlistener(roi,'MovingROI',@updateZoomLimits);
% Close up - note that LimitsChanged also works on uiaxes.
ax = subplot(1,2,2);
addlistener(ax.XAxis, 'LimitsChanged', @updateROI); % extra feature
addlistener(ax.YAxis, 'LimitsChanged', @updateROI);
imshow(I)
% Set initial axis limits
ax.XLim = [roiPosition(1) roiPosition(1)+roiPosition(3)];
ax.YLim = [roiPosition(2) roiPosition(2)+roiPosition(4)];
% Set figure width/height
hf.Position(3:4) = [850 400];
function updateZoomLimits(~, evt)
% Updates axes limits on RHS to match the ROI's position
p = evt.CurrentPosition;
ax.XLim = [p(1) p(1)+p(3)];
ax.YLim = [p(2) p(2)+p(4)];
end
function updateROI(~,~)
% Updates the ROI's position when panning or zooming in/out of the
% image on the right.
p = [ax.XLim; ax.YLim];
roi.Position = [p(1) p(2) p(3)-p(1) p(4)-p(2)];
end
end

その他の回答 (0 件)

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by