Finding center of a line
古いコメントを表示
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. .
採用された回答
その他の回答 (2 件)
Image Analyst
2012 年 1 月 30 日
0 投票
How about using the Pythagorean Theorem? Look up MATLAB's hypot() function.
3 件のコメント
samir
2012 年 1 月 30 日
Image Analyst
2012 年 1 月 30 日
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
2012 年 1 月 31 日
Kevin Moerman
2012 年 1 月 31 日
0 投票
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.
カテゴリ
ヘルプ センター および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!