2 import vtk, qt, ctk, slicer
5 from SegmentEditorEffects
import *
8 """ AutoCompleteEffect is an effect that can create a full segmentation 9 from a partial segmentation (not all slices are segmented or only 10 part of the target structures are painted). 14 AbstractScriptedSegmentEditorAutoCompleteEffect.__init__(self, scriptedEffect)
15 scriptedEffect.name =
'Grow from seeds' 22 import qSlicerSegmentationsEditorEffectsPythonQt
as effects
23 clonedEffect = effects.qSlicerSegmentEditorScriptedEffect(
None)
24 clonedEffect.setPythonSource(__file__.replace(
'\\',
'/'))
28 iconPath = os.path.join(os.path.dirname(__file__),
'Resources/Icons/GrowFromSeeds.png')
29 if os.path.exists(iconPath):
30 return qt.QIcon(iconPath)
34 return """<html>Growing segments to create complete segmentation<br>. 35 Location, size, and shape of initial segments and content of master volume are taken into account. 36 Final segment boundaries will be placed where master volume brightness changes abruptly. Instructions:<p> 37 <ul style="margin: 0"> 38 <li>Use Paint or other offects to draw seeds in each region that should belong to a separate segment. 39 Paint each seed with a different segment. Minimum two segments are required.</li> 40 <li>Click <dfn>Initialize</dfn> to compute preview of full segmentation.</li> 41 <li>Browse through image slices. If previewed segmentation result is not correct then switch to 42 Paint or other effects and add more seeds in the misclassified region. Full segmentation will be 43 updated automatically within a few seconds</li> 44 <li>Click <dfn>Apply</dfn> to update segmentation with the previewed result.</li> 46 If segments overlap, segment higher in the segments table will have priority. 47 The effect uses <a href="http://interactivemedical.org/imic2014/CameraReadyPapers/Paper%204/IMIC_ID4_FastGrowCut.pdf">fast grow-cut method</a>. 53 AbstractScriptedSegmentEditorAutoCompleteEffect.reset(self)
57 AbstractScriptedSegmentEditorAutoCompleteEffect.setupOptionsFrame(self)
69 ' thereby reducing leaks, but requires seed regions to be more evenly distributed in the image.' 70 ' The value is specified as an additional "intensity level difference" per "unit distance."')
75 AbstractScriptedSegmentEditorAutoCompleteEffect.setMRMLDefaults(self)
76 self.scriptedEffect.setParameterDefault(
"SeedLocalityFactor", 0.0)
79 AbstractScriptedSegmentEditorAutoCompleteEffect.updateGUIFromMRML(self)
80 if self.scriptedEffect.parameterDefined(
"SeedLocalityFactor"):
81 seedLocalityFactor = self.scriptedEffect.doubleParameter(
"SeedLocalityFactor")
83 seedLocalityFactor = 0.0
89 AbstractScriptedSegmentEditorAutoCompleteEffect.updateMRMLFromGUI(self)
96 if self.getPreviewNode():
97 self.delayedAutoUpdateTimer.start()
100 import vtkSlicerSegmentationsModuleLogicPython
as vtkSlicerSegmentationsModuleLogic
103 self.
growCutFilter = vtkSlicerSegmentationsModuleLogic.vtkImageGrowCutSegment()
104 self.
growCutFilter.SetIntensityVolume(self.clippedMasterImageData)
106 maskExtent = self.clippedMaskImageData.GetExtent()
if self.clippedMaskImageData
else None 107 if maskExtent
is not None and maskExtent[0] <= maskExtent[1]
and maskExtent[2] <= maskExtent[3]
and maskExtent[4] <= maskExtent[5]:
116 if self.scriptedEffect.parameterDefined(
"SeedLocalityFactor"):
117 seedLocalityFactor = self.scriptedEffect.doubleParameter(
"SeedLocalityFactor")
119 seedLocalityFactor = 0.0
122 startTime = time.time()
124 logging.info(
'Grow-cut operation on volume of {0}x{1}x{2} voxels was completed in {3:3.1f} seconds.'.format(
125 self.clippedMasterImageData.GetDimensions()[0],
126 self.clippedMasterImageData.GetDimensions()[1],
127 self.clippedMasterImageData.GetDimensions()[2],
128 time.time() - startTime))
def updateAlgorithmParameterFromGUI(self)
clippedMasterImageDataRequired
def updateGUIFromMRML(self)
def __init__(self, scriptedEffect)
def computePreviewLabelmap(self, mergedImage, outputLabelmap)
def setupOptionsFrame(self)
def setMRMLDefaults(self)
clippedMaskImageDataRequired
def updateMRMLFromGUI(self)