how to measure distance between points in X using interactive mouse
Show older comments
Hello
I have used edge function to detect the edge of a shape in matlab, now I want to create a GUI where as someone moves their mouse over the image it draws a horizontal line between the points and measures the distance in X between the points, then when the mouse is clicked saves the distance.
Is this possible?
James
Answers (2)
Thomas
on 24 Sep 2012
2 votes
try the imdistline fucntion
5 Comments
James Webster
on 24 Sep 2012
try
ii=imread('name_img.jpg');
imshow(ii);
h=ginput(2) % click two point on image
distance_betwn_mouse_clicks=pdist(h)
or
distance_betwn_mouse_clicks=sqrt((h(2)-h(1))^2+(h(4)-h(3))^2)
instead of imdistline
Image Analyst
on 24 Sep 2012
I think you meant imshow() instead of imread() because the image must be displayed for you to click on it. I don't have distp (base MATLAB or Image Processing Toolbox). You can use hypot() in that case.
Thomas
on 24 Sep 2012
Thanks Image analyst..
emami.m
on 12 Mar 2019
Thanks Thomas.
It was great.
Image Analyst
on 24 Sep 2012
0 votes
Try imfreehand() if you want to trace an arbitrary path. It doesn't "snap" to the next point though, like Photoshop's magnetic lasoo.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!