フィルターのクリア

MATLAB drawrectangle ROI custom wait function difficulty

17 ビュー (過去 30 日間)
Darren Miller
Darren Miller 2020 年 5 月 14 日
コメント済み: Omer Akatekin 2021 年 3 月 22 日
Hi,
In an app I am creating, the user loads in an image then will have to select a square section using drawrectangle. I want to allow the user to move the ROI around for a bit rather than just having it execute the moment the mouse is released, so I have tried using this custom wait function:
I am having trouble progressing in the code though. Here is what I am working with inside my GUI:
figure(1) % create pop out window
imshow(app.I) % show the image
sqSect = drawrectangle; % create rectangle section
[AR,app.pos] = customWait(app, sqSect); % i want the aspect ratio and the position to be returned.
% the aspect ratio is only needed within the function, so I don't include it in the app object
close(h) % after getting the section, I want the pop out window to close
%%*******more stuff here using the app.pos data, not relevant to this issue*******
function [AR,pos] = customWait(~,hROI)
% Listen for mouse clicks on the ROI
l = addlistener(hROI,'ROIClicked',@clickCallback);
% Block program execution
uiwait;
% Remove listener
delete(l);
% Return the current position
pos = hROI.Position;
AR = hROI.AspectRatio;
end
function clickCallback(~,evt)
if strcmp(evt.SelectionType,'double')
uiresume;
end
end
When I run this in my GUI, I can create the rectangle section, but then when I double click it, the pop out window does not close... How do I adjust this to make the pop out window close when I double click the ROI (signifying that I have chosen the right section and am ready to progress to the next stuff)???
EDIT:
the following works in a script, but not in an App for some reason...?
imshow('DSC_4111.png')
h = drawrectangle
pos = customWait(h)
function pos = customWait(hROI)
% Listen for mouse clicks on the ROI
l = addlistener(hROI,'ROIClicked',@clickCallback);
% Block program execution
uiwait;
% Remove listener
delete(l);
% Return the current position
pos = hROI.Position;
end
function clickCallback(~,evt)
if strcmp(evt.SelectionType,'double')
uiresume;
end
end
When I put that in app form, something goes wrong and it gives me that error:
Undefined function 'clickCallback' for input arguments of type 'images.roi.Rectangle'.
Warning: Error occurred while executing the listener callback for event ROIClicked defined for class
images.roi.Rectangle:
Somehow I'm getting an error about the inputs for the clickCallback function even though it works in the exact same format in the app form.. Maybe something to do with the object oriented environment of an app?
  3 件のコメント
Darren Miller
Darren Miller 2020 年 5 月 15 日
Thank you!
I'm pretty sure it has something to do with this answer given by Tommy that I dug up:
Omer Akatekin
Omer Akatekin 2021 年 3 月 22 日
Could you figure it out ? I am having same issue :/

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

採用された回答

Tommy
Tommy 2020 年 5 月 15 日
Store the figure in h so that when you later call close(h), MATLAB knows what h is:
h = figure(1);
  4 件のコメント
Tommy
Tommy 2020 年 5 月 15 日
Ah okay, it seems like after you moved these functions into your app, MATLAB was unable to find clickCallback from within customWait. Where did you put these two functions? It seems like MATLAB can find customWait, based on the error. Does it work if you put clickCallback within customWait? i.e.
function pos = customWait(hROI)
% Listen for mouse clicks on the ROI
l = addlistener(hROI,'ROIClicked',@clickCallback);
% Block program execution
uiwait;
% Remove listener
delete(l);
% Return the current position
pos = hROI.Position;
function clickCallback(~,evt)
if strcmp(evt.SelectionType,'double')
uiresume;
end
end
end
Darren Miller
Darren Miller 2020 年 5 月 15 日
That fixed it! Thank you!

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by