Is there an equivalent to imrect for uiaxes? Or any other way to get coordinates out?

2 visualizaciones (últimos 30 días)
I have an app I unfortunately decided to build in App Designer. Unfortunately, because I need the user to be able to drag to select an ROI on an image. And UIAxes don't take mouse events, and I can't use imrect on uiaxes. Is there any way at all to get this information? I'm willing to go to silly extremes like create an invisible button over the top of the uiaxes to catch the mouse event and then handle the dragging code manually, if needed. Is there something I can do within App Designer? Or, do I need to scrap everything and switch to GUIDE, and kludge together the rest of the tabbed interface by changing objects' visibility? Can I use non-uiaxes axes in App Designer somehow? Would they actually work?

Respuestas (2)

Tim Jackman
Tim Jackman el 24 de Sept. de 2018
Beginning in 18b, you can parent an axes into a uifigure. This means that it is possible to draw the new rectangle ROI in App Designer as follows:
ax = axes(app.UIFigure); drawrectangle(ax);
This page has some more info on current axes support in uifigures:
https://www.mathworks.com/help/matlab/creating_guis/graphics-support-in-app-designer.html
Specific to the rectangle ROI, context menus and mouse pointers are not supported, but the basic interactions should work.
  4 comentarios
Max Nobis
Max Nobis el 28 de Sept. de 2018
Hi Tim, I'm trying to use the code above in Matlab 2018b using programmatically created uifigure with the following code:
ax = axes(uifigure);
h = drawrectangle(ax);
However I'm encountering the following error when I try and move the mouse over the axes. Is there a way to work around this issue?
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Error using matlab.ui.Figure/set
Functionality not supported with figures created with the uifigure function. For more information, see Graphics Support in App Designer.
Error in images.roi.internal.setROIPointer
Error in images.roi.internal.IPTROIPointerManager/motionCallback
Error in images.roi.internal.IPTROIPointerManager>@(src,evt)self.motionCallback(src,evt)
Error in uiwait (line 81)
waitfor (hFigDlg, 'WaitStatus', 'inactive');
Error in images.roi.internal.ROI/draw
Error in drawrectangle (line 187)
h.draw;
> In uiwait (line 81)
In images.roi.internal.ROI/draw
In drawrectangle (line 187)
Many Thanks
Tim Jackman
Tim Jackman el 28 de Sept. de 2018
I haven't seen this warning appear before and I can't reproduce this on my end so there isn't much I can do to resolve it at this point. I'd suggest that you try turning this warning off. To do this, reproduce the warning so it is the last warning you have encountered, then get the message ID:
[~,s] = lastwarn;
Then turn off that warning:
warning('off',s);
You may want to save the message ID and turn it off every time you open your app.
A word of caution: this warning is probably a pretty generic warning and turning it off while you are debugging or developing your app may hide potential problems.
There is some more information about this process here:
https://www.mathworks.com/help/matlab/ref/lastwarn.html

Iniciar sesión para comentar.


Michael Mutersbaugh
Michael Mutersbaugh el 5 de Oct. de 2018
Editada: Michael Mutersbaugh el 5 de Oct. de 2018
Hi Luke, I was having the same problem. What I did was create a new figure, read the image data into it, and offer the user an ROI prompt on THOSE axes instead. This method may not be what you want stylistically, but it works for the GUI.
fig = figure;
imshow(app.current_frame,[]); % Image data stored in property, no axes called
set(fig, 'Position', get(0, 'Screensize')); % Fullscreen image
set(fig,'CloseRequestFcn','') % Prevent pop-up from closing
set(fig, 'MenuBar', 'none');
set(fig, 'ToolBar', 'none');
% Need this while loop because mouse events will prematurely exit
% the ROI functions, even with the CloseRequestFcn turned off
roi = [];
while isempty(roi)
switch app.roi_type
case 'Circular'; roi = imellipse();
case 'Rectangle'; roi = imrect();
case 'Freehand'; roi = imfreehand();
end
end
app.masks{end+1} = roi.createMask(); % Binary matrices stored in cell array
delete(fig)
Once you save the masks, you can use them to manipulate your image data before offering it to the uiaxes.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by