removing previously selected points from image and displaying value?

How do I remove a selected point from an image and display its value?
I want it to prompt the user to select point A on an image, once they do I'd like it to display that value and record it in an array, before asking the user to select point B on an image, how do i do this?
So far I've got this but it doesn't work:
Map=imread('Map.Jpg');
imshow(Map);
uiwait(msgbox('Choose Point A'));
[x,y] = ginput(1); hold on;
plot(x,y,'r+', 'MarkerSize', 50);
disp(ginput(1));
uiwait(msgbox('Choose Point B'));
[x,y] = ginput(2); hold on;
plot(x,y,'r+', 'MarkerSize', 50);
disp(ginput(2));
Please help, tearing hair out!

답변 (2개)

Guillaume
Guillaume 2017년 11월 2일
plot returns a handle to the points/lines it created. To get rid of these lines/points you call the delete function on these handles, so:
uiwait(msgbox('Choose Point A'));
[x,y] = ginput(1); hold on;
hline = plot(x,y,'r+', 'MarkerSize', 50);
disp(ginput(1));
%when you want to get rid of the point:
delete(hline);

댓글 수: 3

I've tried this, it doesn't work and throws up an error:
Map=imread('Map.Jpg');
imshow(Map);
uiwait(msgbox('Choose Point A'));
[x,y] = ginput(1); hold on;
plot(x,y,'r+', 'MarkerSize', 50);
disp(ginput(1));
uiwait(msgbox('Choose Point B'));
delete(hline);
[x,y] = ginput(2); hold on;
plot(x,y,'r+', 'MarkerSize', 50);
disp(ginput(2));
Please use the {}Code button to format your code appropriately in your comments/questions.
A good idea when you say you get an error is to give the full text of the error message rather than letting us guess what it is. In this case, clearly you're going to get the error undefined function or variable hline
I did write: "plot returns a..." So you have to capture that return value. As I have shown:
hline = plot(...
Attempting to
delete(hline)
when you've never created the hline variable in the first place is of course never going to work.
Thanks you were right

댓글을 달려면 로그인하십시오.

KSSV
KSSV 2017년 11월 2일

0 개 추천

doc getpts

댓글 수: 3

Thanks for that, but it doesn't seem to work!
What I'm trying to do is firstly have a message pop up saying "choose point A", allowing the user to make a selection.
After which a message pop up saying "choose point B" allowing the user to make another selection, but now the mark for position A should be removed.
This is the code I'm using: Map=imread('Map.Jpg'); imshow(Map);
uiwait(msgbox('Choose Point A')); [x,y] = ginput(1); hold on; plot(x,y,'r+', 'MarkerSize', 50); disp(ginput(1));
uiwait(msgbox('Choose Point B')); [x,y] = ginput(2); hold on; plot(x,y,'r+', 'MarkerSize', 50); disp(ginput(2));
How do I rectify this to get the functionality I need, at the minute it doesn't work at all.
QAlso how can I get this to function on a single click rather than double clicking as currently.
Why getpts will not work?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Display Image에 대해 자세히 알아보기

질문:

2017년 11월 1일

댓글:

2017년 11월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by