Watershed from markers

Hi!
I’m making my first steps with developing slicer extention and I’ve stuck in one place…
I’ve got MR of sacroiliac. I’m trying to process segmentation of bones using watershed from markers.

I’ve got something like that:

import SimpleITK as sitk
import numpy as np

para = {‘sigma’:2}
itkimg = sitk.GetImageFromArray(imageArray)
itkimg = sitk.DiscreteGaussian(itkimg, para[‘sigma’])
itkimg = sitk.GradientMagnitude(itkimg)

lineimg = sitk.MorphologicalWatershedFromMarkers(itkimg, itkmarker, markWatershedLine=True)

where imageArray is numpy array which contains image.

but I need “itkmarker” image - it should be binary image which contains markers… And I have no idea how to get it. Or maybe there is simplier way to run that algorithm? I’ll be grateful for any tips.

ITK watershed segmentation is implemented in Watershed effect in SegmentEditorExtraEffects extension. The source code is available here: https://github.com/lassoan/SlicerSegmentEditorExtraEffects/blob/master/SegmentEditorWatershed/SegmentEditorWatershedLib/SegmentEditorEffect.py

You are free to clone this implementation and modify it to suit your needs, or you can send pull request with proposed enhancements.

You can use this segmentation method without segment editor user interface as shown in these examples: https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script

1 Like