フィルターのクリア

smart ginput or getpts : how to unselect a point

18 ビュー (過去 30 日間)
adi
adi 2014 年 8 月 10 日
回答済み: Vinny Chandran Suja 2017 年 11 月 3 日
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
Vinny Chandran Suja 2017 年 11 月 3 日
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 Center および File ExchangeVisual Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by