# Joint smoothing in jupyter

**URL:** <https://discourse.slicer.org/t/joint-smoothing-in-jupyter/19875>\
**Category:** Support\
**Created:** [September 26, 2021, 5:28pm UTC](https://discourse.slicer.org/t/joint-smoothing-in-jupyter/19875 "2021-09-26T17:28:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tekk\_ya](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tekk_ya/32/3548_2.png) [@Tekk\_ya](https://discourse.slicer.org/u/Tekk_ya)\
**Post date:** [September 26, 2021, 5:28pm UTC](https://discourse.slicer.org/t/joint-smoothing-in-jupyter/19875/1 "2021-09-26T17:28:32Z")

</div>

Hi,

I want to read two files, one as a volume and another as a segmentation. The segmentation file is the label map including different segments. I am interested in applying a “joint smoothing” on the adjacent segments. I have several questions in this regard:

1. What is the proper way for reading/importing a .nii file as a segmentation with a python code?
2. What is the proper way for selecting the desired segments for the joint smoothing function?
3. What is the correct syntax for activating the joint smoothing function? I have seen several examples for median smoothing like bellow, but I am missing the syntax for enabling the joint smoothing?  
Here is the example for the median filter that I have found:

segmentEditorWidget.setActiveEffectByName(“Smoothing”)  
effect = segmentEditorWidget.activeEffect()  
effect.setParameter(“SmoothingMethod”, “MEDIAN”)  
effect.setParameter(“KernelSizeMm”, 3)  
effect.self().onApply()

Thank you in advance for your help.

---

<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:** [September 27, 2021, 3:39am UTC](https://discourse.slicer.org/t/joint-smoothing-in-jupyter/19875/2 "2021-09-27T03:39:12Z")

</div>

> [@Tekk\_ya](#):
>
> What is the proper way for reading/importing a .nii file as a segmentation with a python code?

The simplest is to use [`slicer.util.loadSegmentation`](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.loadSegmentation) function:

```python
segmentationNode = slicer.util.loadSegmentation('c:/tmp/Segmentation.nii')

```

> [@Tekk\_ya](#):
>
> What is the proper way for selecting the desired segments for the joint smoothing function?

Joint smoothing is applied to all visible segments. You can adjust visibility using [SetSegmentVisibility](http://apidocs.slicer.org/master/classvtkMRMLSegmentationDisplayNode.html#aee65fdd850b42e1b1d1f7117bc082b92) method of the segmentation display node. See examples [here](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#modify-segmentation-display-options).

> [@Tekk\_ya](#):
>
> What is the correct syntax for activating the joint smoothing function?

See description of the Smoothing effect parameters [here](https://slicer.readthedocs.io/en/latest/developer_guide/modules/segmenteditor.html#smoothing).

You need to use `SmoothingMethod` = `JOINT_TAUBIN` and `JointTaubinSmoothingFactor` = the smoothing factor you want to use.

---

<div class="post-metadata">

**Author:** ![Tekk\_ya](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tekk_ya/32/3548_2.png) [@Tekk\_ya](https://discourse.slicer.org/u/Tekk_ya)\
**Post date:** [September 28, 2021, 10:52am UTC](https://discourse.slicer.org/t/joint-smoothing-in-jupyter/19875/3 "2021-09-28T10:52:31Z")

</div>

Dear Andras,

Thank you for your quick reply. I found your suggested links super helpful. Best

---

<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:** [October 7, 2021, 1:46pm UTC](https://discourse.slicer.org/t/joint-smoothing-in-jupyter/19875/4 "2021-10-07T13:46:50Z")

</div>

A post was split to a new topic: [Making joint smoothing faster](https://discourse.slicer.org/t/making-joint-smoothing-faster/20053)
