dicomtools.coordinates module

dicomtools.coordinates.build_image_to_patient_matrix(origin_position, pixel_spacing, row_vec, column_vec, slice_vec=None)

Get a matrix to transform a pixel coordinate to a DICOM patient coordinate. The pixel coordinate corresponds to the center of that pixel/voxel.

The DICOM standard defines the patient coordinate system as:

  • x -> increasing to the left hand side of the patient
  • y -> increasing to the posterior side of the patient
  • z -> increasing toward the head of the patient

source: https://public.kitware.com/IGSTKWIKI/index.php/DICOM_data_orientation

dicomtools.coordinates.build_patient_to_physical_matrix(patient_position)

This function builds a rotation matrix to transform a position in patient coordinates to a position in physical coordinates. This physical coordinate space is arbitrary, but it simply undoes the effect of the patient position. The transformation matrix is the identity matrix for a patient in feet-first prone position. This is useful if you have a robot within the imaging device, and want a consistent coordinate system regardless of the patient position. For example, the up direction will always remain the same for both prone and supine positions. Due to the unknown orientation of the imaging device, we cannot assign direction labels to these physical axes, so you must test it yourself.

Possible patient positions are:

  • HFP = head first-prone
  • HFS = head first-supine
  • HFDR = head first-decibitus right
  • HFDL = head first-decubiturs left
  • FFP = feet first-prone
  • FFS = feet first-supine
  • FFDR = feet first-decibitus right
  • FFDL = feet first-decibitus left

source: https://public.kitware.com/IGSTKWIKI/index.php/DICOM_data_orientation

dicomtools.coordinates.build_translation_matrix(translation)

For a given translation vector, this function builds the corresponding transformation matrix.

Example:

>>> build_translation_matrix([4,5,6])
array([[1 0 0 4]
       [0 1 0 5]
       [0 0 1 6]
       [0 0 0 1]])
dicomtools.coordinates.expand_transformation_dimension(transformation, new_size, move_translation)

This function takes an \(n \times n\) transformation matrix and expands it to a \(new\_size \times new\_size\) matrix. It expands the array, fills in ones along the diagonal, and moves the translation values to the new right column if requested.

Example:

>>> test = np.array([[1,2,3],[4,5,6],[0,0,1]])
>>> test
array([[1 2 3]
       [4 5 6]
       [0 0 1]])

>>> expand_transformation_dimension(test, 6, True)
array([[1 2 0 0 0 3]
       [4 5 0 0 0 6]
       [0 0 1 0 0 0]
       [0 0 0 1 0 0]
       [0 0 0 0 1 0]
       [0 0 0 0 0 1]])
dicomtools.coordinates.transform_vectors(transformation_matrix, vectors)

This function applies (LHS) the \(n \times n\) transformation matrix to a list of vectors and returns a list of the transformed vectors.

The vectors can be any length less than n. The vectors will be zero-filled so that they have length \(n-1\). If the input is one-dimensional, it is assumed that a single vector was given and a one-dimensional vector will be returned.