How to set non-uniform spacing

I am reading in 2D multislice MRI data which contains e.g. 3 slices using the SetImportPointer for registration. The Z-slices are positioned at -101.25, -33.75 and -18.75 mm. I am confused on how to use the image->SetSpacing option in this case since the distance between slices are different.
If I set originZ=-101.25 and spacingZ=67.5, the 3rd slice will be at 33.75mm and NOT at -18.75mm.
Anyone knows on how to work around this issue.

You can to resample the image to have uniform spacing along each axis. The best way the we have found to do this is to create a grid transform, which transforms the slice corner coordinates to the correct physical positions. If you use this transform as input for vtkImageReslice filter then it will provide you the image at any resolution you ask.

The full implementation is available in 3D Slicer’s DICOM importer. ITK, too, has grid transforms (you can either use displacement field transform or bspline transform), so you should be able to the method to ITK without any complications. You are free to take the implementation and use it in your own application, but of course you are probably much better off if you build your tool or application by customizing/extending 3D Slicer platform, instead of copying over features one by one.

1 Like

ITK assumes uniform spacing along each dimension. A better option is to resample to uniform spacing as Andras suggests. A dirty option is to ignore variability in spacing - this is useful to check whether something works without big investment into correctness.