# Which Interpolator to Resample Image and its segmentation Mask

**URL:** <https://discourse.itk.org/t/which-interpolator-to-resample-image-and-its-segmentation-mask/689>\
**Category:** Algorithms\
**Tags:** rotation, interpolator, mask\
**Created:** [February 19, 2018, 5:33pm UTC](https://discourse.itk.org/t/which-interpolator-to-resample-image-and-its-segmentation-mask/689 "2018-02-19T17:33:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jsphine](https://discourse.itk.org/letter_avatar_proxy/v4/letter/j/cc9497/32.png) [@Jsphine](https://discourse.itk.org/u/Jsphine)\
**Post date:** [February 19, 2018, 5:33pm UTC](https://discourse.itk.org/t/which-interpolator-to-resample-image-and-its-segmentation-mask/689/1 "2018-02-19T17:33:26Z")

</div>

Dear community,

I have a set of CT images and their masks (segmentations). What I want to do is to rotate/resample them without losing the correspondence between the image and the mask.  
Using the LinearInterpolator yields good images but bad segmentation masks, and using the NearestNeighbourInterpolator yields better masks but bad images.  
Using the LinearInterpolator on the image and the NearestNeighbourInterpolator on the mask yields an image and a mask that don’t really match.  
What would you suggest in this situation?

Thank you very much in advance!  
Josy

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [February 19, 2018, 5:56pm UTC](https://discourse.itk.org/t/which-interpolator-to-resample-image-and-its-segmentation-mask/689/2 "2018-02-19T17:56:41Z")

</div>

> [@Jsphine](#):
>
> Using the LinearInterpolator on the image and the NearestNeighbourInterpolator on the mask yields an image and a mask that don’t really match.

I would suggest you double check this. This should work. How they don’t match? Small, one-pixel or so discrepancies, or large misalignments?

You can also try `BSplineInterpolateImageFunction` instead of linear for improved quality.

---

<div class="post-metadata">

**Author:** ![Jsphine](https://discourse.itk.org/letter_avatar_proxy/v4/letter/j/cc9497/32.png) [@Jsphine](https://discourse.itk.org/u/Jsphine)\
**Post date:** [February 19, 2018, 7:04pm UTC](https://discourse.itk.org/t/which-interpolator-to-resample-image-and-its-segmentation-mask/689/3 "2018-02-19T19:04:50Z")

</div>

Thanks for the quick reply and the suggestion.  
The discrepancies are really small. When I view the image and its mask in ITK-Snap, I notice a couple of extra pixels in the mask that go over the edge of the original image; I was worrying that it would influence the sensitivity of the neural network I’m planning to feed them to.

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)\
**Post date:** [February 20, 2018, 2:33am UTC](https://discourse.itk.org/t/which-interpolator-to-resample-image-and-its-segmentation-mask/689/4 "2018-02-20T02:33:07Z")

</div>

If you rotate a binary mask and you need to minimize information loss then you can

- resample the binary labelmap on a much finer grid than the original image (subdivide each voxel to 2x2x2 or 3x3x3 voxels), and/or
- store resampling result in a fractional labelmap (where occupancy is not represented by a single bit but a scalar value).

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [February 20, 2018, 3:12pm UTC](https://discourse.itk.org/t/which-interpolator-to-resample-image-and-its-segmentation-mask/689/5 "2018-02-20T15:12:44Z")

</div>

> [@lassoan](#):
>
> store resampling result in a fractional labelmap (where occupancy is not represented by a single bit but a scalar value).

There is a representation problem here that needs some thought and analysis for your particular problem and application.

Another option, is to use a distance map filter to convert the mask to a level set, where zero value is representation of the surface. This would readily resample well.
