How to turn off interpolation for discrete label segmentation image?

I’m rendering a segmentation overlay with discrete labels 1, 2, 4 and background 0 in the image. And looks like I have to pick interpolation type between Linear and Nearest. Either interpolation type renders the data incorrectly, with a thin layer of interpolated “labels” surrounding the structure.

image

Is there a way to turn off interpolation for label image rendering? Or should I use some other ways rather than ImageSlice + ImageMapper?

Thanks!

What does your lookup table look like? Does it have defined colors for each of your label values?

Thanks for the reply!

Just want to confirm that the Nearest Neighbor Interpolation is not taking average of the neighboring voxels, right? I’m asking because now I suspect the issue might be caused by the incorrect interpolation in the downsampling from the upstream data pipeline (not vtk-js related).

Here’s my lut configuration. The original segmentation should only have label 4. But now 1, 2, 3, are also showing up at the border.

image

const seg_lut = vtkColorTransferFunction.newInstance();
seg_lut.setIndexedLookup(true);
seg_lut.setMappingRange(0, 4);
seg_lut.addRGBPoint(0, 0, 0, 0);
seg_lut.addRGBPoint(1, 1, 0, 0);
seg_lut.addRGBPoint(2, 0, 1, 0);
seg_lut.addRGBPoint(3, 0, 0, 1);
seg_lut.addRGBPoint(4, 1, 0.87, 0.74);

seg_actor.getProperty().setRGBTransferFunction(0, seg_lut);
seg_actor.getProperty().setColorLevel(2);
seg_actor.getProperty().setColorWindow(4);

const ofun = vtkPiecewiseFunction.newInstance();
ofun.addPoint(0, 0);
ofun.addPoint(1, 0.8);

seg_actor.getProperty().setScalarOpacity(ofun);
seg_actor.getProperty().setInterpolationTypeToNearest();

Nearest should not be taking averages of neighbors, so I would also double check that you only have a label value of 4 in the final labelmap.

It was my data issue. Thanks for confirming about the interpolation type!