# How to interpret skimage orientation to straighten images?

I have a bunch of images that I am trying to straighten so the images are horizontal (major axis is horizontal) but I don't understand the orientation output from regionprops method in skimage. How to convert it into degrees ? What is the axis reference for the output angle ?

Here is the skimage doc:

orientation : float. Angle between the 0th axis (rows) and the major axis of the ellipse that has the same second moments as the region, ranging from -pi/2 to pi/2 counter-clockwise.

My question: Given the orientation, how do I calculate the angle in degrees to rotate the image so that the major axis is horizontal with skimage?

## Code sample

Basically, the main major and minor axis of this object belong to index 1 of the pandas dataframe. The orientation of the object is -1.184075 and should belong to the major axis.

from skimage.measure import label, regionprops_table

# connected pixels of same label get assigned a value
label_img = label(binary_image_here)
props = regionprops_table(label_img, properties=('centroid',
'bbox',
'orientation',
'major_axis_length',
'minor_axis_length'))

df = pd.DataFrame(props) Based on the doc you provide, orientation is in radians, ranging from -pi/2 to pi/2 counter-clockwise:

orientation : float. Angle between the 0th axis (rows) and the major axis of the ellipse that has the same second moments as the region, ranging from -pi/2 to pi/2 counter-clockwise.

Moreover, as it is said in the regionpropos doc, since 0.16.0, they use "rc" corrdinates everywhere. They say for the majority of computation you could find the old results with a simple transformation, but for others, it is more complicated, such as the orientation:

For example, the new orientation is π/2 plus the old orientation.

Which means that the right formula to get the angle you want is this one:

angle_in_degrees = orientation * (180/np.pi) + 90


And the orientation refers to this angle on the image: Now: If you want your major axis and the 0th axis align, then rotate your image by -angle_in_degrees:

from skimage.transform import rotate
rotate(image, -angle_in_degrees, resize=True)

• Ah ok, I see. So, I convert radians to degrees and then rotate so the total equals either -90 or 90 depending on whether the radian was positive of negative. If the radian is negative, convert the radian to degrees and add the remaining degree value so the total is -90 degrees and vice-versa. – zipline86 Aug 4 at 11:31
• I have updated my answer. Is it clearer now how you should proceed ? – etiennedm Aug 4 at 11:54
• Ah yes much clearer, thanks! One thing though. The major axis in the example picture I have looks like your first image; however, the orientation by skimage is negative (negative also in degrees) and not positive. Why is that? Should I also be considering the position of minor axis in that case? – zipline86 Aug 4 at 12:04
• You are right, I did not understand it first but it comes from an update they have done. To compute the right angle you should add pi/2 to the orientation (or 90 to the angle in degrees). I have added that to the answer. – etiennedm Aug 4 at 13:56