Nuclear orientation



how is the x-axis calculated in the orientation function contained in the measureObjectSizeShape? In fact, I need to calculate the orientation of several nuclei but I am not sure if the angles obtained with the function are relative to a common x-axis.



From the MeasureObjectSizeShape Help:

Orientation: The angle (in degrees ranging from -90 to 90 degrees) between the x-axis and the major axis of the ellipse that has the same second-moments as the region.

I assume the positive x-axis points to the right, with positive angles moving up and vice versa. What I don’t know is what direction the major-axis has, as it is a line with no directionality (right??).

I would suggest an empirical approach – construct an image with ellipses of various angles and report the values.
(Side note: I have always wondered the same, but never had a specific need to check this out further! :slight_smile:)

FYI - I looked at the code and got as far as here (, but then it wasn’t obvious to me how the moments related to the coordinate system for certain. (@agoodman? @mcquin? @bcimini)


@David_Logan Take all of the below with a giant asterisk, because I’m not totally certain. Also, feel free to say if I’m not making sense.)

I think the major axis DOES have directionality, because what it’s using to calculate all the ellipse features is a matrix looking at the relative representation (bincount) in x vs y (or i vs j in the CP code) of the objects relative to their own centers. So you actually start with position information in there, which you can then ignore for things like length but can take advantage of to determine orientation.

If you look at the help for the numpy function, it says:

The quadrant (i.e., branch) is chosen so that arctan2(x1, x2) is the signed angle in radians between the ray ending at the origin and passing through the point (1,0), and the ray ending at the origin and passing through the point (x2, x1).

My interpretation of that is that it sets one end of the ellipse major axis as 0,0, sets the other according to the values calculated from the x/y information, and then draws the angle to the positive x axis.


Sorry I missed ping again. @bcimini what you say sounds good. But getting back to the original question, since we didn’t really answer it, I still was not sure of the coordinate system and how the angles are measured. So I just did it empirically:

Here’s the input image with lots of ellipses (thanks Matlab):

and here is a pipeline I made:
test_DL_orientation_angles.cppipe (7.3 KB)

The output is here:

Inspecting the individual grains, it seems to me to indicate that the coordinate system for the Orientation measure is like this:

Do you agree @bcimini ? It seems a little counter-intuitive, since it seems to originate on what most would consider the negative x axis. Comments?

Validating CellProfiler Object Orientation

I agree with your assessment of what the coordinate system actually is, but I also agree that it definitely seems backwards to what I expected. Worth filing an issue?