Is there an equivalent to imrect for uiaxes? Or any other way to get coordinates out?
4 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
Tim Jackman
2018-9-24
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 个评论
Max Nobis
2018-9-28
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
2018-9-28
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
Michael Mutersbaugh
2018-10-5
编辑:Michael Mutersbaugh
2018-10-5
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!