Joint smoothing in jupyter

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.

The simplest is to use slicer.util.loadSegmentation function:

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

Joint smoothing is applied to all visible segments. You can adjust visibility using SetSegmentVisibility method of the segmentation display node. See examples here.

See description of the Smoothing effect parameters here.

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

1 Like

Dear Andras,

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

1 Like

A post was split to a new topic: Making joint smoothing faster