2012 Project Week Breakout Session: SimpleITK

From NAMIC Wiki
Jump to: navigation, search
Home < 2012 Project Week Breakout Session: SimpleITK

This session will focus on demonstrating how to use SimpleITK with Slicer.

  1. How to compile Slicer for SimpleITK integration
  2. How to build a CLI module with SimpleITK
  3. How to pass images to/from Slicer in python


import SimpleITK as sitk
import sitkUtils as su
help(su.PullFromSlicer)
# PullFromSlicer(NodeName)
# Given a slicer MRML image name, return the SimpleITK image object.
help(su.PushToSlicer)
# PushToSlicer(sitkimage, NodeName, makeBackgroundImage=False)
# Given a SimpleITK image, push it back to slicer for viewing
help(sitk.OtsuThreshold)
# OtsuThreshold(Image image, uint8_t inInsideValue = 1u,
# uint8_t inOutsideValue = 0u,
# uint32_t inNumberOfHistogramBins = 128u) -> Image
help(sitk.Cast)
help(sitk.CannyEdgeDetection)
help(sitk.SobelEdgeDetection)
mrhead=su.PullFromSlicer("MRHead")
mrhead.GetDirection()
mrhead.GetSpacing()
mrhead.GetOrigin()
mask=sitk.OtsuThreshold(mrhead,1,0)
su.PushToSlicer(mask,"MyMask",1)
def MakeOutline(FillSize):
dilate=sitk.DilateObjectMorphology(mask,FillSize)
erode=sitk.ErodeObjectMorphology(dilate,FillSize)
float_image=sitk.Cast(erode,sitk.sitkFloat32)
edge=sitk.SobelEdgeDetection(float_image)
return edge
edge=MakeOutline(7)
su.PushToSlicer(edge,"Edge",1)
PointSource=sitk.Image(64,64,64,sitk.sitkFloat32)
PointSource[31,31,31]=100
for sigma in range(1,9,3):
gsmooth=sitk.RecursiveGaussian(PointSource,sigma)
su.PushToSlicer(gsmooth,"GaussSmooth"+str(sigma),True)