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

6 views (last 30 days)
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?

Answers (2)

Tim Jackman
Tim Jackman on 24 Sep 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:
Specific to the rectangle ROI, context menus and mouse pointers are not supported, but the basic interactions should work.
Tim Jackman
Tim Jackman on 28 Sep 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:
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:

Sign in to comment.

Michael Mutersbaugh
Michael Mutersbaugh on 5 Oct 2018
Edited: Michael Mutersbaugh on 5 Oct 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();
app.masks{end+1} = roi.createMask(); % Binary matrices stored in cell array
Once you save the masks, you can use them to manipulate your image data before offering it to the uiaxes.


Find more on Maintain or Transition figure-Based Apps in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by