# Nearest Neighbor implementation

**URL:** <https://discourse.slicer.org/t/nearest-neighbor-implementation/29529>\
**Category:** Development\
**Tags:** python, cropping\
**Created:** [May 18, 2023, 2:15pm UTC](https://discourse.slicer.org/t/nearest-neighbor-implementation/29529 "2023-05-18T14:15:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![osmandogan](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@osmandogan](https://discourse.slicer.org/u/osmandogan)\
**Post date:** [May 18, 2023, 2:15pm UTC](https://discourse.slicer.org/t/nearest-neighbor-implementation/29529/1 "2023-05-18T14:15:43Z")

</div>

Hello. I am doing a volume crop operation in a study I have been working on. And I want to use the “Nearest Neighborn” feature from the interpolator features in the “Volume Crop” module. How can I add the “Nearest Neighborn” attribute to my code?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 18, 2023, 7:01pm UTC](https://discourse.slicer.org/t/nearest-neighbor-implementation/29529/2 "2023-05-18T19:01:30Z")

</div>

You can change the interpolation mode programmatically by modifying properties of the crop volume parameter node:

```python
parameterNode = getNode('CropVolumeParameters')
mode = slicer.vtkMRMLCropVolumeParametersNode.InterpolationNearestNeighbor
parameterNode.SetInterpolationMode(mode)

```

---

<div class="post-metadata">

**Author:** ![osmandogan](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@osmandogan](https://discourse.slicer.org/u/osmandogan)\
**Post date:** [May 18, 2023, 10:23pm UTC](https://discourse.slicer.org/t/nearest-neighbor-implementation/29529/3 "2023-05-18T22:23:22Z")

</div>

Thank you very much, that’s exactly what I was looking for 😃
