Finding center of a line
Mostrar comentarios más antiguos
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. .
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 30 de En. de 2012
0 votos
How about using the Pythagorean Theorem? Look up MATLAB's hypot() function.
3 comentarios
samir
el 30 de En. de 2012
Image Analyst
el 30 de En. de 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
el 31 de En. de 2012
Kevin Moerman
el 31 de En. de 2012
0 votos
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 comentario
samir
el 31 de En. de 2012
Categorías
Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!