@@ -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