How to calculate distance in centimeters using IMDISTLINE?
Mostra commenti meno recenti
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?
Risposta accettata
Più risposte (2)
Roche de Guzman
il 30 Gen 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 Commento
Image Analyst
il 30 Gen 2021
I like how you put in so many comments. I wish everyone would do that.
Matt J
il 4 Ott 2013
0 voti
Multiply by the length (in cm) of one pixel.
9 Commenti
karishma
il 4 Ott 2013
Image Analyst
il 4 Ott 2013
karishma, did you not see the FAQ entry explanation, with code, that I gave? Does that not explain it clearly enough?
Image Analyst
il 4 Ott 2013
Run the attached demo if you want to see it in action.
leylin fatqiyah
il 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
il 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
il 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
il 12 Feb 2015
Modificato: Image Analyst
il 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
il 12 Feb 2015
this is my image https://www.mathworks.com/matlabcentral/answers/177673-how-to-measuring-curve-line-of-an-image
thank you
Categorie
Scopri di più su Build Interactive Tools in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!