You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how can i calculate distance between two points on an image
10 views (last 30 days)
Show older comments
hallow
i want to calculate distance between two point on a body image. and to measure angle between two lines on an image............
Answers (2)
Image Analyst
on 9 Jan 2014
Use imdistline() to do it interactively. Or use hypot() or sqrt() if you know the coordinates.
43 Comments
Saliha
on 11 Jan 2014
i want multiple point's measurement on a single image ...... compare and compute their value and then want to save their value for further use... imdistline() draws only single line.
Image Analyst
on 11 Jan 2014
Well, how do you expect those lines to get there ?
If you know where they are already, just use hypot() or sqrt() like I said.
Saliha
on 12 Jan 2014
Edited: Walter Roberson
on 21 Jan 2014
i want to calculte something like this....
please visit this image...
i want to calculte distance between two feets, angle of knee and hip to which extent these bend during walk... and want differentiate using some geometrical mthods.
Image Analyst
on 12 Jan 2014
Link doesn't work. And I believe I answered the question about how to find distances between two points: use imdistline to do it interactively or use sqrt() if you know the locations from some other method, like image segmentation or whatever.
Image Analyst
on 12 Jan 2014
You didn't ask how to find the vertices, only how to measure the distance between them. Presumably you're following some paper that tells you how to find the vertices. Anyway, I don't know how - I'd have to look up some papers just like you're probably doing.
Saliha
on 13 Jan 2014
right.... I'm following and I've some innovative idea on it. but i don't know how to calculate and evaluate to satisfy my point..................
Saliha
on 13 Jan 2014
actually i want to give these point as mouse input and after that want different calculations on it....... kindly tell me how it is possible using matlab........
Image Analyst
on 13 Jan 2014
Edited: Image Analyst
on 13 Jan 2014
Please reread my answer. That tells you how. If you think it doesn't, then please explain why. I don't know if you overlooked in the help that imdistline() lets the user specify endpoints with the mouse. And I'm sure you learned the Pythagorean theorem in high school - it uses sqrt(). It shouldn't be very hard at all, but if you need me to actually write the lines of code for you, let me know. Try to adapt the examples in imdistline().
Saliha
on 15 Jan 2014
I've run an example but.......... can't drive my desired point .... don't know that by taking this topic I'll fall in maze :'(
Saliha
on 15 Jan 2014
but if u know about any software of "gait analysis or recognition" then pleaseeeeeeeeeeeeeee send me I'll be thankful :(
Image Analyst
on 15 Jan 2014
16.7.4.5 Walking, Gait Recognition, Gait Analysis
16.7.4.5.1 Walking, Gait Recognition, University of Southampton
16.7.4.5.2 Cyclic Motion, Periodic Motion, for Walking and Gait Recognition
16.7.4.5.3 Human ID Using Gait, Recognition of People Through Gait
16.7.4.5.4 Gait Analysis, Depth, 3-D Data, 3-D from Gait
16.7.4.5.5 Gait Analysis, Diagnosis of Difference, Joint Information, Motion Capture
16.7.4.5.6 Human Motion Capture, Joint Information, Special Activities
16.7.4.5.7 Human Motion Capture, Dance Activities
Saliha
on 15 Jan 2014
are these links have software for gait ?????? or just papers etc?? i found nothing from these....
Walter Roberson
on 15 Jan 2014
Image Analyst
on 15 Jan 2014
Yeah, you'd think they could of chosen a better name. Of course, maybe that was on purpose.
Saliha
on 20 Jan 2014
still i didn't find any solution :(
will u again suggest any idea by analyzing above picture ???
Image Analyst
on 20 Jan 2014
If imdistline() is too challenging, you can use ginput() and sqrt():
imshow('cameraman.tif');
promptMessage = sprintf('Left-Click on the two points.');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
[x, y] = ginput(2)
distance = sqrt((x(2)-x(1))^2 + (y(2)-y(1))^2)
message = sprintf('The distance is %.3f pixels.', distance);
uiwait(helpdlg(message));
Saliha
on 21 Jan 2014
I've done it iteratively but at every iteration values of variables are being replaced.
Saliha
on 21 Jan 2014
Edited: Image Analyst
on 21 Jan 2014
I'm unable to understand. would you like to elaborate? But i'll try to do it... if not succeeded then i'll consult again.
Image Analyst
on 21 Jan 2014
Show the code for the loop and the array variable you want to set inside it.
Walter Roberson
on 21 Jan 2014
for K = 1 : 10
[x(K,:) y(K,:)] = ginput(2)
distance(K) = sqrt((x(K,2)-x(K,1))^2 + (y(K,2)-y(K,1))^2)
ang(K) = atan2( y(K,2)-y(K,1), x(K,2)-x(K,1) );
message = sprintf('The distance is %.3f pixels, angle %.3f', distance(K), ang(K));
uiwait(helpdlg(message));
end
Saliha
on 22 Jan 2014
Edited: Walter Roberson
on 22 Jan 2014
image analyst..............code is here... at every iteration values of x, y overwrite. i want to save all values.
n=9;
imshow('img.png');
promptMessage = sprintf('Left-Click on the two points.');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
for i=1:n;
if strcmpi(button, 'Cancel')
return;
end
[x, y] = ginput(2)
distance = sqrt((x(2)-x(1))^2 + (y(2)-y(1))^2)
message = sprintf('The distance is %.3f pixels.', distance);
uiwait(helpdlg(message));
end
Walter Roberson
on 22 Jan 2014
Use what I showed right above, except change "for K = 1 : 10" to "for K = 1 : n".
Note: your strcmpi() test should be before the "for" loop.
Saliha
on 22 Jan 2014
walter roberson ............
this calculates angle from x and y xes. i want to calculate by giving both lines as input.... as shown in above image..... like < ..... this compute at single line
Walter Roberson
on 22 Jan 2014
Geometrically, it is the product of the magnitudes of the two vectors and the cosine of the angle between them.
and that tells you that you can find the angle as arccos of the dot product divided by the product of the two magnitudes.
I was more concerned about showing you how to save the values which was the part you were having trouble with.
Note: In order to define the dot product, you need to have a starting point to calculate the distances to the two given points. You do not have that in your code: you only have the two points and you asked to find the distance between those two points; that will go directly from one point to another, not from one point to the branch point to the second point.
Saliha
on 24 Jan 2014
can i use imdistlint with ginput?????? and still need help measuring angle between these drawn two lines.....
Image Analyst
on 24 Jan 2014
imdistline can only handle two points. If you need 3, you can use imline() where you can daisy-chain any number of line segments.
Saliha
on 24 Jan 2014
i want to use ginput() or somethign like this as parameter to imdistline().
and also want to use it Iteratively
Image Analyst
on 24 Jan 2014
Okay, that's fine. ginput() gives giant crosshairs instead of rubber band line, but if that's what you want, that's fine.
Saliha
on 24 Jan 2014
its good for me to see the code..... if u send as good gesture. I'll be thankful.
Image Analyst
on 24 Jan 2014
I gave code for clicking on points, and Walter gave code for getting angle. Can't you combine them and get something that works? If you can't do that much, how are you going to do the rest of your algorithm, which I'm sure is probably going to be a lot more complicated than that?
Saliha
on 25 Jan 2014
I've combined it . and run it many times. that angle is not calculated as i want. this calculate it from one point only. as getanglefromhorizontal() of imdistline().
Image Analyst
on 25 Jan 2014
Attach your latest code and we might look at it over the weekend if we get time.
Walter Roberson
on 25 Jan 2014
ginput(3) would allow the user to click on one limb, then click on the join at the body, and then click on the other limb; with the points and the order known, calculating the angle becomes a matter of applying the trig formula I gave earlier.
Usman Siddique
on 16 Feb 2017
is u are still working on that project ?
1 Comment
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)