How to calculate distance in centimeters using IMDISTLINE?
Show older comments
i want to find out height of a sleeping infant. for that i want to find out the distance in cm. using 'imdistline' i'm getting the distance in pixels but how to convert that in cm?
Accepted Answer
More Answers (2)
Roche de Guzman
on 30 Jan 2021
global h; h = imdistline; % activates the fx for drawing and measuring line
setLabelTextFormatter(h,'measure'); % message
addNewPositionCallback(h,@ShowDistance); % new position callback
%% Custom fx
function ShowDistance(pos)
global h xc yc; % sets line handles and x and y conversion factors to global
X = pos(:,1)*xc; Y = pos(:,2)*yc; % converts x and y positions from px to target unit
d = norm(diff([X Y])); % distance in target unit
setLabelTextFormatter(h,[num2str(d,'%.1f') ' target unit']); % updates measurement
end
1 Comment
Image Analyst
on 30 Jan 2021
I like how you put in so many comments. I wish everyone would do that.
Matt J
on 4 Oct 2013
0 votes
Multiply by the length (in cm) of one pixel.
9 Comments
karishma
on 4 Oct 2013
Image Analyst
on 4 Oct 2013
karishma, did you not see the FAQ entry explanation, with code, that I gave? Does that not explain it clearly enough?
Image Analyst
on 4 Oct 2013
Run the attached demo if you want to see it in action.
leylin fatqiyah
on 11 Feb 2015
is imdistline only used to measure a line? what if i wanna measure a curve from an image? such as an arc??
Image Analyst
on 11 Feb 2015
It's only used for a line. You can use imline() or roipolyold() to get coordinates of a polygon. Or you can use imfreehand(). I've attached a demo of imfreehand(), though not for drawing a curve and measuring the length of it.
leylin fatqiyah
on 12 Feb 2015
thaks for the respons. i'll try it. i have another questions,, what about imellips? can half of the ellips is used to measuring the curve line? thank you
Image Analyst
on 12 Feb 2015
Edited: Image Analyst
on 12 Feb 2015
I don't see how. POST YOUR IMAGE IN A NEW QUESTION , not here , and perhaps I'd change my mind or give you other suggestions.
leylin fatqiyah
on 12 Feb 2015
this is my image https://www.mathworks.com/matlabcentral/answers/177673-how-to-measuring-curve-line-of-an-image
thank you
Categories
Find more on Build Interactive Tools 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!