Exposing `vtkImageInterpolator` border mode to the public API

In VTK, SetBorderMode() method is a public method, and pyvista should be able to expose it via resample() without any changes to VTK itself. I’m not sure why pyvista does not already do so.

There are reasons why VTK doesn’t implement the constant mode:

  1. it requires an additional piece of information (the constant)
  2. having a default constant value of zero can lead to surprising results

To illustrate (2), consider a typical CT image. Let’s say the raw CT data is in the range [0,4095] and that we also have a copy of the CT image converted to Hounsfield units in the range [-1024,3071] (here, the conversion is done by subtracting 1024 from the raw data). Ideally, we expect to get the same results (to within roundoff error) if we interpolate before converting to Housfield units as compared to interpolating after converting to Hounsfield units.

However if we use the constant border mode with a constant of zero, we would get different results! In order to get the same results, the user would have to be savvy enough to use a constant of zero when working in Hounsfield units, and a constant of 1024 when working with the raw pixel data.

The clamp mode gives the same result in either case, because the clamp mode is invariant under linear transformations of the pixel values. The same is true of the repeat and mirror methods (and the reflect method). The constant mode stands out from the rest because it is not invariant.

Also, consider what most of the border modes are trying to achieve: they are extrapolating the data values past the edge of the image. If the image is smooth (as most medical images are) then we expect that the data values in the border will have similar values to their neighbors in the image. That’s what the clamp mode provides.

I’m not actually opposed to adding a constant mode to vtkImageInterpolator, I’m just trying to illustrate why it isn’t my first choice when interpolating images. Any of the other modes will generally give superior results.

1 Like