Hello,
I am working on writing my own gantry tilt correction function in Python. The function takes in a list of correctly ordered DICOM images loaded by pydicom
, corrects each slice, and returns a corrected 3D image.
def correct_gantry_tilt(images):
corrected_images = np.zeros((len(images), images[0].Rows, images[0].Columns))
for image_index, image in enumerate(images):
gantry_tilt = image.GantryDetectorTilt
slice_location = image.SliceLocation
inter_slice_distance = image.SliceThickness * np.cos(np.radians(gantry_tilt))
image = sitk.GetImageFromArray(image.pixel_array[:,:,np.newaxis])
transform = sitk.AffineTransform(3)
transform.SetCenter(image.TransformContinuousIndexToPhysicalPoint(np.array(image.GetSize())/2))
transform.SetTranslation((0, 0, (slice_location-images[0].SliceLocation)/inter_slice_distance))
transform.Shear(0, 2, np.radians(gantry_tilt))
output_shape = (512, 512, 512)
resampled_image = sitk.Resample(image, output_shape, transform, sitk.sitkLinear, [-output_shape[0]//2,0,0], image.GetSpacing(), image.GetDirection())
resampled_image = sitk.GetArrayFromImage(resampled_image)
corrected_images[image_index,:,:] = np.amax(resampled_image, axis=2)
return corrected_images
The current implementation does not seem to get the tilt angle correct and is slow (this is because of the large output_shape
that is being reduced with np.amax()
). Does anyone have any insight into how to efficiently correct gantry tilt of a single DICOM image?