필터 지우기
필터 지우기

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