Unable to show the result from filter - SimpleITK

Hello,
What I am trying to achieve is to apply BinaryMorphologicalOpeningImageFilter to a vtkMRMLModelNode.

These are the steps that I follow:

  1. Add the stl model as Segmentation into Slicer
  2. Convert Segmentation into vtkMRMLLabelMapVolumeNode and then into vtkMRMLScalarVolumeNode
  3. Apply the filter to the Volume

import SimpleITK as sitk
import sitkUtils as su

seg = slicer.util.getNode(‘segm’)
labelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLLabelMapVolumeNode’,‘LabelMap’)
outputvolumenode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLScalarVolumeNode”, ‘OutputVolume’)
slicer.modules.segmentations.logic().ExportAllSegmentsToLabelmapNode(seg, labelmapVolumeNode)
sef = slicer.modules.volumes.logic().CreateScalarVolumeFromVolume(slicer.mrmlScene,outputvolumenode, labelmapVolumeNode)

filter = sitk.BinaryMorphologicalOpeningImageFilter()
filter.SetKernelRadius((1,1,1))
su.PullVolumeFromSlicer(outputvolumenode)
result = filter.Execute(im)

But I am not sure how should I display the result into a vtkMRMLModelNode to Slicer and verify that the filter is working.
Thanks

Hi @siaeleni -

It looks like you missing the conversion of the slicer volume to a simpleitk image - this code should help:

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Running_an_ITK_filter_in_Python_using_SimpleITK

# Run processing
inputImage = sitkUtils.PullVolumeFromSlicer(inputVolumeNode)
filter = sitk.SignedMaurerDistanceMapImageFilter()
outputImage = filter.Execute(inputImage)
sitkUtils.PushVolumeToSlicer(outputImage, outputVolumeNode)
2 Likes