Last Updated: February 25, 2016
·
2.012K
· somada141

Resample 3D image data in a vtkImageData object using the vtkImageReslice class

Assuming we have a vtkImageData object under the name of image this is how we'd go about resampling that image data with a factor of 2. Here we assume that image has a spacing of 1.0 mm across all axes

resliceFilter = vtk.vtkImageReslice()
resliceFilter.SetInput(image)
resliceFilter.SetOutputSpacing(0.5, 0.5, 0.5)
resliceFilter.SetInterpolationModeToCubic()
resliceFilter.Update()
imageResampled = resliceFilter.GetOutput()

The resampled vtkImageData object is stored under imageResampled. Note that resampling is achieved by setting the output spacing to 0.5 mm through the SetOutputSpacing method.

While the above snippet uses cubic interpolation, vtkImageReslice offers nearest-neighbor and linear interpolation as well. All it takes is replacing SetInterpolationModeToCubic with SetInterpolationModeToNearestNeighbor or SetInterpolationModeToLinear