Skip to content

Instantly share code, notes, and snippets.

@agirault
Created October 8, 2020 22:31
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save agirault/60a72bdaea4a2126ecd08912137fe641 to your computer and use it in GitHub Desktop.
Save agirault/60a72bdaea4a2126ecd08912137fe641 to your computer and use it in GitHub Desktop.
Image Orientation in Dicom

Ref: http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.2.html#sect_C.7.6.2.1.1

Definition of the Orientation Matrix in Dicom

The Image Orientation (Patient) dicom tag is (0020,0037), and is defined as 6 elements: "Ax, Ay, Az, Bx, By, Bz".

When described as a 3x3 rotation matrix R, it's equivalent to:

    Ax  Bx  Cx
R = Ay  By  Cy
    Az  Bz  Cz

where [C] = [A] × [B] (cross-product)

A 3D volume is a set of k 2D images, each of them with i columns and j rows. We can define the coordinates of that dataset with (i, j, k). Now, if we want to go from the volume data coordinates to world (or patient) coordinate (x, y, z), we need to do a transformation. Let's say - for the sake of the explanation - that we'll restrict the transformation from one to the other to the rotation R (there is also scaling by the spacing and translation by the origin/position, but I'll skip that here). We can then define the transformation like this:

(x, y, z) = R(i, j, k)

or in matrix form:

x     Ax  Bx  Cx     i
y  =  Ay  By  Cy  *  j
z     Az  Bz  Cz     k

which gives those equations:

x = i * Ax + j * Bx + k * Cx
y = i * Ay + j * By + k * Cy
z = i * Az + j * Bz + k * Cz

Why LPS is the coordinate system in Dicom

According to the dicom standard...

...the x-axis is increasing to the left hand side of the patient. The y-axis is increasing to the posterior side of the patient. The z-axis is increasing toward the head of the patient [superior].

This means that the dicom world (or patient) coordinate system is LPS:

  • X is Right to Left (RL)
  • Y is Anterior to Posterior (AP)
  • Z is Inferior to Superior (IS)

Dataset with Axial scans?

If we want to look at the Axial axis in world space, it means that we need to face towards the Superior or the Inferior direction (IS axis), which is the third axis (Z) in the LPS system. If we need the scans (2D images) to be Axial, that means that k (the data coordinate that increases for each slice) needs to be aligned with z:

  • z = k: the scan faces Superior
  • z = -k: the scan faces Inferior

Based on the equations for x, y and z in the first section, it then means that:

  • Az = 0
  • Bz = 0
  • Cz = 1 or Cz = -1

To keep A, B, C orthogonal, and to stay axis-aligned (meaning x, y, z each need to be equal to either i, j, k or their opposite, but not a mix of them which would require interpolating), the only possible orientation strings for axial scans are then:

  • Facing Superior (Cx = 1):
    • 1, 0, 0, 0, 1, 0 (identity)
    • -1, 0, 0, 0, -1, 0 (180° around Z(SI))
    • 0, -1, 0, 1, 0, 0 (-90° around ZSI))
    • 0, 1, 0, -1, 0, 0 (90° around Z(SI))
  • Facing Inferior (Cx = -1):
    • 1, 0, 0, 0, -1, 0 (180° around x(RL))
    • -1, 0, 0, 0, 1, 0 (180° around y(PA))
    • 0, 1, 0, 1, 0, 0 (-90° around z(SI) + 180° around x(RL) or 90° around z(SI) + 180° around y(PA))
    • 0, -1, 0, -1, 0, 0 (90° around z(SI) + 180° around x(RL) or -90° around z(SI) + 180° around y(PA))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment