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!

Answers (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 Comments

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.

Sign in to comment.

doc getpts

3 Comments

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.

Sign in to comment.

Categories

Asked:

on 1 Nov 2017

Commented:

on 2 Nov 2017

Community Treasure Hunt

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

Start Hunting!