MATLAB: How to draw a line along the major axis as found with regionprops

majoraxislengthregionprops

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?

Best Answer

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.