Selecting a row of image pixels as ROI from GUI

Hello,
Does anyone know of a way to use GUIDE to allow a user to select a 1-dimensional row (vector) of pixels in an image as a region of interest (i.e. the straight edge of an object)? I have an edge detected (logical) version of the colour image, and want to use the user's selection to find the closest edge coordinates that correspond to that image.
Many thanks in advance for any help you can throw my way.

 Accepted Answer

Make a GUI with pushbutton and axis
Display the image on that axis
The button callback will be something like this
[x,y,button]=ginput(number)
This will allow you to get the coordinates of the pixels, x is a vector with the vertical positions and y is a vector with the horizontal positions, number is the number of points you let the user mark on the picture.
If you want the user to decide how many points he wants do something like this
button=1;xx=[];yy=[];
while button==1
[x,y,button]=ginput(1);
plot(x,y,'rx') %mark the point
if button==1
xx=[xx x];yy=[yy y];
end
end
This will save the points the user selected into xx and yy vectors until the user presses another button than 1 (left mouse button on my system)

5 Comments

That's great, thanks!! I think this is exactly what I need... However, I am a bit confused as to what x and y show. From your first example, my workspace shows x as a 1x101 double vector and y as a 1x41 double vector, when only 1 input is made. Can this function tell me the pixel coordinates of x and y?
Thanks again for all your help!!
oops, apologies! It seems I already had an x and y from a previous run and I forgot to clear before trying your example... It works fine, I was just being very stupid.
One side question: Do you happen to know if I can magnify the image so that the user can see the pixels more clearly. Would this be done on 'imshow'? I have tried the 'InitialMagnification' tag, but it doesn't seem to have an effect.
If you are using the GUIDE to build your guide you just need to add the zoom tools with default code to the figure toobar :)
The Pan function will also be very useful
You might also want to insert another button to initialize the figure (load it again into the axis), kind of GUI reset.
Great! Thanks for your help!! :)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!