I am working on resampling and interpolating some CT scans to have isotropic voxel spacing (
[1, 1, 1]). I have tried two approaches that both execute without error, but I am not sure why the first approach looks odd when viewed in Slicer.
The first approach uses the original CT as a reference image but overwrites to isotropic spacing. This approach keeps the same size (e.g. 512x512x134).
While the second approach derives a new size based on the desired spacing, such that the resampled image has the same volume in physical space (mm).
import SimpleITK as sitk file = "example.nrrd" img = sitk.ReadImage(file)
## First Approach (keep the same size) rs = sitk.ResampleImageFilter() rs.SetReferenceImage(img) rs.SetOutputSpacing([1, 1, 1]) img2 = rs.Execute(img) sitk.WriteImage(img2, "imgSameSize.nrrd")
## Second Approach (keep the same volume) rs2 = sitk.ResampleImageFilter() new_x = round(img.GetSize() * img.GetSpacing() / 1) new_y = round(img.GetSize() * img.GetSpacing() / 1) new_z = round(img.GetSize() * img.GetSpacing() / 1) rs2.SetOutputSpacing([1, 1, 1]) rs2.SetSize([new_x, new_y, new_z]) rs2.SetOutputDirection(img.GetDirection()) rs2.SetOutputOrigin(img.GetOrigin()) rs2.SetTransform(sitk.Transform()) rs2.SetInterpolator(sitk.sitkLinear) img3 = rs.Execute(img) sitk.WriteImage(img3, "imgDiffSize.nrrd")
I’m hoping that someone here could offer insight into whether I have made any mistakes in either approach? I come from the
R world so I apologize if my code is not adhering to python best practices.