How do I draw a line along the major axis as found with regionprops

I have used the regionprops to find the MajorAxisLenth of each object in my image. How do I draw a line along the major axis?

 採用された回答

Walter Roberson
Walter Roberson 2011 年 6 月 29 日

3 投票

If you get the Centroid and Orientation and MajorAxisLength properties, then this becomes mostly a traditional y = m*x + b problem, where m is tan() of the Orientation and b is chosen so that the line passes through the Centroid.
Or even easier, MajorAxisLength * cosd(Orientation) to get the x axis coordinate difference, center that around the Centroid, likewise MajorAxisLength * sind(Orientation) to get the y coordinate difference, center that around the Centroid; then line() between the two endpoints.

4 件のコメント

Pooja lepcha
Pooja lepcha 2013 年 10 月 15 日
How do I get the other points meaning the x and y co-ordinates of the ends of the major axis on the object?
Eric T
Eric T 2014 年 6 月 23 日
編集済み: Eric T 2014 年 6 月 23 日
Pooja: say you have deltax and deltay, and centroid coordinate is x,y. Then the line ends are:
xVals=[x-deltax/2 x+deltax/2]
yVals=[y-deltay/2 y+deltay/2]
line(xVals,yVals) will plot the line.
Abhinav Agarwal
Abhinav Agarwal 2021 年 10 月 29 日
What is delta x and delta y?
Image Analyst
Image Analyst 2021 年 10 月 30 日
It's the width of the bounding box.
Now they have bwferet() so look into that.

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by