Finding center of a line
Show older comments
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. .
Accepted Answer
More Answers (2)
Image Analyst
on 30 Jan 2012
0 votes
How about using the Pythagorean Theorem? Look up MATLAB's hypot() function.
3 Comments
samir
on 30 Jan 2012
Image Analyst
on 30 Jan 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
on 31 Jan 2012
Kevin Moerman
on 31 Jan 2012
0 votes
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.
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!