lassoan
(Andras Lasso)
August 29, 2020, 2:21pm
2
This easily doable in two steps:
push/pull volume node to/from SimpleITK using sitkUtils (see example )
convert the volume node to/from segmentation node (see example )
There are several Segment Editor effects that use SimpleITK, which can serve as a complete example (that even show how to implement interactive segmentation tools, which require some user input):
# Run segmentation algorithm
import SimpleITK as sitk
import sitkUtils
# Read input data from Slicer into SimpleITK
labelImage = sitk.ReadImage(sitkUtils.GetSlicerITKReadWriteAddress(mergedLabelmapNode.GetName()))
backgroundImage = sitk.ReadImage(sitkUtils.GetSlicerITKReadWriteAddress(masterVolumeNode.GetName()))
# Run watershed filter
featureImage = sitk.GradientMagnitudeRecursiveGaussian(backgroundImage, float(self.scriptedEffect.doubleParameter("ObjectScaleMm")))
del backgroundImage
f = sitk.MorphologicalWatershedFromMarkersImageFilter()
f.SetMarkWatershedLine(False)
f.SetFullyConnected(False)
labelImage = f.Execute(featureImage, labelImage)
del featureImage
# Pixel type of watershed output is the same as the input. Convert it to int16 now.
if labelImage.GetPixelID() != sitk.sitkInt16:
labelImage = sitk.Cast(labelImage, sitk.sitkInt16)
# Write result from SimpleITK to Slicer. This currently performs a deep copy of the bulk data.
sitk.WriteImage(labelImage, sitkUtils.GetSlicerITKReadWriteAddress(mergedLabelmapNode.GetName()))
This file has been truncated. show original