Skip to content

Commit 8b312ee

Browse files
authored
Merge pull request #132 from goma1256/#92_RotationMatrixCorrection
Issue #92 : rotation matrix correction
2 parents 485fe50 + 8992c98 commit 8b312ee

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

rt_utils/image_helper.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ def get_pixel_to_patient_transformation_matrix(series_data):
161161
row_direction, column_direction, slice_direction = get_slice_directions(first_slice)
162162

163163
mat = np.identity(4, dtype=np.float32)
164-
mat[:3, 0] = row_direction * row_spacing
165-
mat[:3, 1] = column_direction * column_spacing
164+
#The following might appear counter-intuitive, i.e. multiplying the row direction with the column spacing and vice-versa
165+
#But is the correct way to create the transformation matrix, see https://nipy.org/nibabel/dicom/dicom_orientation.html
166+
mat[:3, 0] = row_direction * column_spacing
167+
mat[:3, 1] = column_direction * row_spacing
166168
mat[:3, 2] = slice_direction * slice_spacing
167169
mat[:3, 3] = offset
168170

@@ -183,9 +185,11 @@ def get_patient_to_pixel_transformation_matrix(series_data):
183185
# inv(M) = [ inv(rotation&scaling) -inv(rotation&scaling) * translation ]
184186
# [ 0 1 ]
185187

188+
#The following might appear counter-intuitive, i.e. dividing the row direction with the column spacing and vice-versa
189+
#But is the correct way to create the inverse transformation matrix, see https://nipy.org/nibabel/dicom/dicom_orientation.html
186190
linear = np.identity(3, dtype=np.float32)
187-
linear[0, :3] = row_direction / row_spacing
188-
linear[1, :3] = column_direction / column_spacing
191+
linear[0, :3] = row_direction / column_spacing
192+
linear[1, :3] = column_direction / row_spacing
189193
linear[2, :3] = slice_direction / slice_spacing
190194

191195
mat = np.identity(4, dtype=np.float32)

0 commit comments

Comments
 (0)