Slicer  5.3
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
SegmentEditorFillBetweenSlicesEffect.py
Go to the documentation of this file.
1 import os
2 
3 import qt
4 import vtk
5 
6 from SegmentEditorEffects import *
7 
8 
10  """ AutoCompleteEffect is an effect that can create a full segmentation
11  from a partial segmentation (not all slices are segmented or only
12  part of the target structures are painted).
13  """
14 
15  def __init__(self, scriptedEffect):
16  AbstractScriptedSegmentEditorAutoCompleteEffect.__init__(self, scriptedEffect)
17  scriptedEffect.name = 'Fill between slices'
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/FillBetweenSlices.png')
27  if os.path.exists(iconPath):
28  return qt.QIcon(iconPath)
29  return qt.QIcon()
30 
31  def helpText(self):
32  return """<html>Interpolate segmentation between slices<br>. Instructions:
33 <p><ul>
34 <li>Create complete segmentation on selected slices using any editor effect.
35 Segmentation will only expanded if a slice is segmented but none of the direct neighbors are segmented, therefore
36 do not use sphere brush with Paint effect and always leave at least one empty slice between segmented slices.</li>
37 <li>All visible segments will be interpolated, not just the selected segment.</li>
38 <li>The complete segmentation will be created by interpolating segmentations in empty slices.</li>
39 </ul><p>
40 Masking settings are ignored. If segments overlap, segment higher in the segments table will have priority.
41 The effect uses <a href="https://insight-journal.org/browse/publication/977">morphological contour interpolation method</a>.
42 <p></html>"""
43 
44  def computePreviewLabelmap(self, mergedImage, outputLabelmap):
45  import vtkITK
46  interpolator = vtkITK.vtkITKMorphologicalContourInterpolator()
47  interpolator.SetInputData(mergedImage)
48  interpolator.Update()
49  outputLabelmap.DeepCopy(interpolator.GetOutput())
50  imageToWorld = vtk.vtkMatrix4x4()
51  mergedImage.GetImageToWorldMatrix(imageToWorld)
52  outputLabelmap.SetImageToWorldMatrix(imageToWorld)