# How to turn off interpolation for discrete label segmentation image?

**URL:** https://discourse.vtk.org/t/how-to-turn-off-interpolation-for-discrete-label-segmentation-image/10706
**Category:** Web
**Created:** [February 15, 2023, 11:12pm UTC](https://discourse.vtk.org/t/how-to-turn-off-interpolation-for-discrete-label-segmentation-image/10706 "2023-02-15T23:12:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jilei-hao](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jilei-hao/32/5581_2.png) [@jilei-hao](https://discourse.vtk.org/u/jilei-hao)
#### Post date: [February 15, 2023, 11:12pm UTC](https://discourse.vtk.org/t/how-to-turn-off-interpolation-for-discrete-label-segmentation-image/10706/1 "2023-02-15T23:12:59Z")

</div>

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](https://discourse.vtk.org/uploads/default/original/2X/4/403956b3eb0e19d1cec552234f7d922d979afb55.png)

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

Thanks!

---

<div class="post-metadata">

### Author: ![Forrest](https://discourse.vtk.org/user_avatar/discourse.vtk.org/forrest/32/300_2.png) [@Forrest](https://discourse.vtk.org/u/Forrest)
#### Post date: [February 16, 2023, 3:30pm UTC](https://discourse.vtk.org/t/how-to-turn-off-interpolation-for-discrete-label-segmentation-image/10706/2 "2023-02-16T15:30:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jilei-hao](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jilei-hao/32/5581_2.png) [@jilei-hao](https://discourse.vtk.org/u/jilei-hao)
#### Post date: [February 16, 2023, 3:52pm UTC](https://discourse.vtk.org/t/how-to-turn-off-interpolation-for-discrete-label-segmentation-image/10706/3 "2023-02-16T15:52:07Z")

</div>

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](https://discourse.vtk.org/uploads/default/original/2X/7/7ac27c5757fa571292dc1b1ab63418ea1be64806.png)

```javascript
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();

```

---

<div class="post-metadata">

### Author: ![Forrest](https://discourse.vtk.org/user_avatar/discourse.vtk.org/forrest/32/300_2.png) [@Forrest](https://discourse.vtk.org/u/Forrest)
#### Post date: [February 16, 2023, 3:58pm UTC](https://discourse.vtk.org/t/how-to-turn-off-interpolation-for-discrete-label-segmentation-image/10706/4 "2023-02-16T15:58:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jilei-hao](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jilei-hao/32/5581_2.png) [@jilei-hao](https://discourse.vtk.org/u/jilei-hao)
#### Post date: [February 17, 2023, 1:56am UTC](https://discourse.vtk.org/t/how-to-turn-off-interpolation-for-discrete-label-segmentation-image/10706/5 "2023-02-17T01:56:06Z")

</div>

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