Slicer  4.8
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
SegmentEditorGrowFromSeedsEffect.py
Go to the documentation of this file.
1 import os
2 import vtk, qt, ctk, slicer
3 import logging
4 from SegmentEditorEffects import *
5 
7  """ AutoCompleteEffect is an effect that can create a full segmentation
8  from a partial segmentation (not all slices are segmented or only
9  part of the target structures are painted).
10  """
11 
12  def __init__(self, scriptedEffect):
13  AbstractScriptedSegmentEditorAutoCompleteEffect.__init__(self, scriptedEffect)
14  scriptedEffect.name = 'Grow from seeds'
16  self.clippedMasterImageDataRequired = True # master volume intensities are used by this effect
17  self.growCutFilter = None
18 
19  def clone(self):
20  import qSlicerSegmentationsEditorEffectsPythonQt as effects
21  clonedEffect = effects.qSlicerSegmentEditorScriptedEffect(None)
22  clonedEffect.setPythonSource(__file__.replace('\\','/'))
23  return clonedEffect
24 
25  def icon(self):
26  iconPath = os.path.join(os.path.dirname(__file__), 'Resources/Icons/GrowFromSeeds.png')
27  if os.path.exists(iconPath):
28  return qt.QIcon(iconPath)
29  return qt.QIcon()
30 
31  def helpText(self):
32  return """<html>Growing segments to create complete segmentation<br>.
33 Location, size, and shape of initial segments and content of master volume are taken into account.
34 Final segment boundaries will be placed where master volume brightness changes abruptly. Instructions:<p>
35 <ul style="margin: 0">
36 <li>Use Paint or other offects to draw seeds in each region that should belong to a separate segment.
37 Paint each seed with a different segment. Minimum two segments are required.</li>
38 <li>Click <dfn>Initialize</dfn> to compute preview of full segmentation.</li>
39 <li>Browse through image slices. If previewed segmentation result is not correct then switch to
40 Paint or other effects and add more seeds in the misclassified region. Full segmentation will be
41 updated automatically within a few seconds</li>
42 <li>Click <dfn>Apply</dfn> to update segmentation with the previewed result.</li>
43 </ul><p>
44 Masking settings are bypassed. If segments overlap, segment higher in the segments table will have priority.
45 The effect uses <a href="https://www.spl.harvard.edu/publications/item/view/2761">fast grow-cut method</a>.
46 <p></html>"""
47 
48 
49  def reset(self):
50  self.growCutFilter = None
51  AbstractScriptedSegmentEditorAutoCompleteEffect.reset(self)
52  self.updateGUIFromMRML()
53 
54  def computePreviewLabelmap(self, mergedImage, outputLabelmap):
55  import vtkSlicerSegmentationsModuleLogicPython as vtkSlicerSegmentationsModuleLogic
56 
57  if not self.growCutFilter:
58  self.growCutFilter = vtkSlicerSegmentationsModuleLogic.vtkImageGrowCutSegment()
59  self.growCutFilter.SetIntensityVolume(self.clippedMasterImageData)
60 
61  self.growCutFilter.SetSeedLabelVolume(mergedImage)
62  self.growCutFilter.Update()
63 
64  outputLabelmap.DeepCopy( self.growCutFilter.GetOutput() )