Difference between revisions of "2012 Project Week Breakout Session: SimpleITK"
From NAMIC Wiki
(Created page with ' To be populated by Hans/David.') |
Hjmjohnson (talk | contribs) |
||
| Line 1: | Line 1: | ||
| − | + | This session will focus on demonstrating how to use SimpleITK with Slicer. | |
| + | |||
| + | # How to compile Slicer for SimpleITK integration | ||
| + | # How to build a CLI module with SimpleITK | ||
| + | # How to pass images to/from Slicer in python | ||
| + | |||
| + | |||
| + | <pre> | ||
| + | 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) | ||
| + | </pre> | ||
Latest revision as of 16:30, 18 June 2012
Home < 2012 Project Week Breakout Session: SimpleITKThis session will focus on demonstrating how to use SimpleITK with Slicer.
- How to compile Slicer for SimpleITK integration
- How to build a CLI module with SimpleITK
- 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)