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)))) center=get_center(moving_image) transform = sitk.Euler3DTransform(center,1,1,1,(0,0,0)) img_trans=sitk.Resample(moving_image,moving_image, transform,sitk.sitkLinear, 0) print(sitk.GetArrayFromImage(img_trans).max) print(img_trans.GetOrigin())
Code is a bit confusing, let’s simplify.
First, get the physical center of an image:
center = image.TransformContinuousIndexToPhysicalPoint([sz/2 for sz in image.GetSize()])
Now let’s look at the transform:
transform = sitk.Euler3DTransform(center,1,1,1,(0,0,0))
The meaning of the above transform is rotate around the
center point using the ZXY Euler order with a rotation of 1 radian (~57 degrees) around each axis, no translation.
Finally, a simpler resampling statement which is equivalent to the original code, and visualizing results, can be done as:
image_resampled = sitk.Resample(image, transform) sitk.Show(image_resampled)
The meaning of the above resampling is, use the original image grid and resample the original image onto it by applying a rotation to each of the grid points.
You can gain a better understanding of what is happening if you work in 2D and use a 90degree rotation. Highly recommend going over the resampling notebook.
Thank you very much.
Thank you very much. I still have a problem. After the rotation of the image, some parts will be missing. How can we enlarge the visual field of the image to get the complete image? My images are private and can’t be released. My images are 3D.