I am trying to reorient images along the hippocampus main axis. I can replicate the results of 06_segmentation_and_shape_analysis.html, but since it centers the image on the corner of the bounding box, it is less than ideal for my application.
I’ve tried to put the orientation matrix into a VersorTransform (so that I can later only keep the rotation along the x-axis), and while the resampling aligns the image properly, the axes end-up being permuted. I have forced my image’s orientation to be 1,1,1, so this shouldn’t be the source of the issue. Any ideas what I’m doing wrong?
# Force orientation/origin for debug hippo.SetOrigin([0,0,0]) hippo.SetDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]) # Compute the bounding box orientation filter LabelShape = sitk.LabelShapeStatisticsImageFilter() LabelShape.ComputeOrientedBoundingBoxOn() LabelShape.Execute(hippo) # Extract Bounding box orientation matrix direction_mat = LabelShape.GetOrientedBoundingBoxDirection(1) aligned_image_direction = [direction_mat, direction_mat, direction_mat, direction_mat, direction_mat, direction_mat, direction_mat, direction_mat, direction_mat ] # This is following the exemple resampler = sitk.ResampleImageFilter() resampler.SetOutputDirection(aligned_image_direction) resampler.SetOutputOrigin(LabelShape.GetOrientedBoundingBoxOrigin(1)) resampler.SetOutputSpacing(hippo.GetSpacing()) resampler.SetSize(hippo.GetSize()) hippo_res1 = resampler.Execute(hippo)
This is the Sagittal view as expected
Now using the Versor Transform
# Using a VersorRigid3DTransform rotation = sitk.VersorRigid3DTransform() rotation.SetMatrix(direction_mat); rotation.SetCenter(LabelShape.GetOrientedBoundingBoxOrigin(1)) hippo_res2 = sitk.Resample(hippo,hippo.GetSize(),rotation.GetInverse(), sitk.sitkNearestNeighbor, hippo.GetOrigin(), hippo.GetSpacing(), hippo.GetDirection())
This is the Sagittal view
And the Coronal view