Finding center of a line
Mostra commenti meno recenti
Hi i need to find the center of a line.A robot needs to foolow this line in real time but my problem is how to find the center of a line.I used bwmorph(image,'thin',inf); and i get the that my thick line thins to a line with 1 pixel size.
so now the only thing that i need is to calculate the distance between the center of my image (blue +) and the line so i could say to my robot move to left so that the center of the line is equal to the image center. .
Risposta accettata
Più risposte (2)
Image Analyst
il 30 Gen 2012
0 voti
How about using the Pythagorean Theorem? Look up MATLAB's hypot() function.
3 Commenti
samir
il 30 Gen 2012
Image Analyst
il 30 Gen 2012
You're right, if the "line" is not straight. You can't just find the centroid because the centroid may not line on or in the line. You could try bwboundaries() and play around with what that returns.
samir
il 31 Gen 2012
Kevin Moerman
il 31 Gen 2012
0 voti
If its a straight line then you could simply take the mean of your line coordinates (or even centre of gravity of the image object).
If the line is curved then sum up line segments to get total curve length (calculate point-to-point distances and use cumsum for instance), and then solve for (e.g. interpolate) what coordinate describes half of the curve length.
1 Commento
samir
il 31 Gen 2012
Categorie
Scopri di più su Image Processing Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!