MATLAB drawrectangle ROI custom wait function difficulty
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Darren Miller
el 14 de Mayo de 2020
Comentada: Omer Akatekin
el 22 de Mzo. de 2021
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 comentarios
Respuesta aceptada
Tommy
el 15 de Mayo de 2020
Store the figure in h so that when you later call close(h), MATLAB knows what h is:
h = figure(1);
4 comentarios
Tommy
el 15 de Mayo de 2020
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
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!