Draw points on UIAxes until you press a button in APP DESIGNER

29 次查看(过去 30 天)
Hi, I have a problem, I'm developing an application using the app designer but there comes a moment when I have to be able to select points from an image I show in a UIAxes using the drawcircle function.
What I need is to be able to enter points (without having defined how many in advance) until I press on a status button, but I also need to save the position of the points, what I came up with was this but it doesn't work well
i = 1;
ROI = zeros(8,2);
while app.AplicarInterpolacinButton.Value == 0
a = drawpoint(app.UIAxes);
ROI(i,:) = a.Position;
i = i + 1;
end
Thank you.
  5 个评论
Alejandro Fernández
Yes but when I press the button it doenst stop, i have to enter another point... and i'm usiing r2020a

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2020-6-9
编辑:Adam Danz 2020-6-9
Once drawpoint() is called, it waits for a response and the waiting time cannot be interrupted until you either draw a point, press escape, or close the figure. Since the rest of your while-loop is very fast, there is very little time between iterations so there is very little time that your code can detect that the stop-button was pressed. Therefore, it's very highly likely that any randomly timed button press will occur during the drawpoint() execution and the button press will not be detected until either a point is drawn or the user presses escape or the figure is closed. There's no way to programmatically end the drawpoint() wait-time.
If you can figure out an algorithm that detects when enough points were drawn, you could end the while-loop prior to initializing the next drawpoint.
To end loop when escape is pressed or figure is closed
When you end drawpoint by pressing escape, it returns an empty position value. When you end drawpoint by closing the figure, a "handle to deleted point" is returned.
To continually draw points until esc is pressed or the fig is closed, just test of those conditions.
userStopped = false;
pointhandles = gobjects();
while ~userStopped
a = drawpoint();
if ~isvalid(a) || isempty(a.Position)
% End the loop
userStopped = true;
else
% store point object handle
pointhandles(end+1) = a;
end
end
  10 个评论
Ely Raz
Ely Raz 2021-10-15
编辑:Ely Raz 2021-10-15
I am trying to run the above code in a GUI and mark points over an image. I can not move or delete the points as clicking with both mouse buttons generate more points, can it be fixed? Is it possible to mark the points with text? and Furthermre, after pressing the ESC, how can I get the coordinates?
function StartButtonPushed(app, event)
imshow('peppers.png','Parent',app.ImageAxes);
userStopped = false;
pointhandles = gobjects();
while ~userStopped
a = drawpoint(app.ImageAxes);
if ~isvalid(a) || isempty(a.Position)
% End the loop
userStopped = true;
else
% store point object handle
pointhandles(end+1) = a;
end
end
disp(pointhandles)
end
Michael Vinsome
Michael Vinsome 2022-7-25
For everything else:
function draw
idx = 0;
positions = [];
fig = figure(1);
ax = axes;
userStopped = false;
btn = uicontrol('Parent',gcf,'Style','pushbutton','string','Undo!', 'Callback', @undo);
while ~userStopped
a = drawpoint();
idx = idx + 1;
if ~isvalid(a) || isempty(a.Position)
userStopped = true;
else
positions(:,:,idx) = a.Position;
assignin("base", "positions", positions)
end
end
end
function undo(src, event)
ud = findobj('Type','images.roi.Point');
delete(ud);
draw
end

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by