smart ginput or getpts : how to unselect a point

9 次查看(过去 30 天)
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

回答(2 个)

Vinny Chandran Suja
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

Image Analyst
Image Analyst 2014-8-10
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.

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by