How to visualize regionprop object orientation using imshow.

6 views (last 30 days)
I would like to plot a line along the major axis of an object. For example, given:
A = [ 0 0 0 0 0;
0 0 0 0 0;
0 0 1 0 0;
0 1 0 0 0;
0 0 0 0 0;];
imshow(A); hold on;
props = regionprops(A,'Orientation','Centroid');
c = props.Centroid;
Creates an image with an object that has a major axis at 45 degrees to the X axis. Regioprops agrees:
>> props.Orientation
ans =
45
If I understand my trigonometry:
x = c(1) + 10 * cosd(props.Orientation);
y = c(2) + 10 * sind(props.Orientation);
line([c(1) x],[c(2) y])
should produce a line along the Major Axis of the object. Instead it produces a line perpendicular to the major axis. Why is the line not along the Major Axis of the object?

Accepted Answer

Image Analyst
Image Analyst on 14 Nov 2013
y goes downward for images. You'd need
y = c(2) - 10 * sind(props.Orientation);
  2 Comments
Animesh Biswas
Animesh Biswas on 23 Mar 2022
Hi,
I have a follow up question here. I would want to plot many orientation (line as mentioned above) of an object with color gradient, or with different colors. Please suggest how can I do that.
Thank you
Image Analyst
Image Analyst on 23 Mar 2022
Not sure what you want. Maybe you could use markers with plot() if the line needs a color gradient along the line, or maybe you could specify 'Color' in line(). Show a screen mockup of what you want.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!