smart ginput or getpts : how to unselect a point
9 views (last 30 days)
Show older comments
I need a GUI for selecting many points in an image. I want Matlab to delete a previously selected point if I click it again, or click on it with the right mouse button (not just the last point I selected, but any of the previous points!). how do I do this? tnx
0 Comments
Answers (2)
Vinny Chandran Suja
on 3 Nov 2017
As ImageAnalyst said there is no inbuild feature in ginput that supports your requirement. However, I came up with the following workaround:
(a) Query single points from ginput in a loop
(b) [For selecting points] If the input was from a left click, add the data to an array/structure
(c) [For removing points] If the input was from a right click, query the nearest neighbor from the array/structure and remove it from the dataset.
A minimal example is below for:
while(1)
[Imx, Imy , mb]=ginput(1);
if mb==1
data(:,count)=[Imx,Imy];
% optionally display points
handlesPointsInImage(:,count)=plot(Imx,Imy,'.r');
end
if mb==3
ind=knnsearch(data(1:2,:)',[Imx,Imy]);
data(:,ind)=[];
% if points were displayed
delete(handlesPointsInImage(:,ind));
handlesPointsInImage(:,ind)=[];
end
if mb==2 % Middle mouse button exits the pick mode
break;
end
count = count +1;
end
0 Comments
Image Analyst
on 10 Aug 2014
I don't think there is a way for ginput(), but for getpts(), the help says: "Pressing Backspace or Delete removes the previously selected point." getpts() has the advantage that it drops down a marker where you click whereas ginput() does not.
0 Comments
See Also
Categories
Find more on Data Exploration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!