def get_center(img):
"""
This function returns the physical center point of a 3d sitk image
:param img: The sitk image we are trying to find the center of
:return: The physical center point of the image
"""
width, height, depth = img.GetSize()
return img.TransformIndexToPhysicalPoint((int(np.ceil(width/2)),
int(np.ceil(height/2)),
int(np.ceil(depth/2))))
def convert_to_hfs(image,reference_image, interpolator=sitk.sitkLinear, direction=None):
rangefilter = sitk.MinimumMaximumImageFilter()
rangefilter.Execute(image)
default_value = rangefilter.GetMinimum()
if direction is None:
direction = reference_image.GetDirection()
image_center = get_center(image)
rotation = sitk.Euler3DTransform()
rotation.SetCenter(image_center)
rotation.SetMatrix(direction)
resampled_image = sitk.Resample(image, reference_image, rotation,interpolator , default_value)
return resampled_image