本文整理汇总了Python中SegmentStatistics.SegmentStatisticsLogic类的典型用法代码示例。如果您正苦于以下问题:Python SegmentStatisticsLogic类的具体用法?Python SegmentStatisticsLogic怎么用?Python SegmentStatisticsLogic使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SegmentStatisticsLogic类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_SegmentStatisticsBasic
def test_SegmentStatisticsBasic(self):
"""
This tests some aspects of the label statistics
"""
self.delayDisplay("Starting test_SegmentStatisticsBasic")
import vtkSegmentationCorePython as vtkSegmentationCore
import vtkSlicerSegmentationsModuleLogicPython as vtkSlicerSegmentationsModuleLogic
import SampleData
from SegmentStatistics import SegmentStatisticsLogic
self.delayDisplay("Load master volume")
sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1()
self.delayDisplay("Create segmentation containing a few spheres")
segmentationNode = slicer.vtkMRMLSegmentationNode()
slicer.mrmlScene.AddNode(segmentationNode)
segmentationNode.CreateDefaultDisplayNodes()
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
# Geometry for each segment is defined by: radius, posX, posY, posZ
segmentGeometries = [[10, -6,30,28], [20, 0,65,32], [15, 1, -14, 30], [12, 0, 28, -7], [5, 0,30,64], [12, 31, 33, 27], [17, -42, 30, 27]]
for segmentGeometry in segmentGeometries:
sphereSource = vtk.vtkSphereSource()
sphereSource.SetRadius(segmentGeometry[0])
sphereSource.SetCenter(segmentGeometry[1], segmentGeometry[2], segmentGeometry[3])
sphereSource.Update()
segment = vtkSegmentationCore.vtkSegment()
segment.SetName(segmentationNode.GetSegmentation().GenerateUniqueSegmentID("Test"))
segment.AddRepresentation(vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationClosedSurfaceRepresentationName(), sphereSource.GetOutput())
segmentationNode.GetSegmentation().AddSegment(segment)
self.delayDisplay("Compute statistics")
segStatLogic = SegmentStatisticsLogic()
segStatLogic.computeStatistics(segmentationNode, masterVolumeNode)
self.delayDisplay("Check a few numerical results")
self.assertEqual( segStatLogic.statistics["Test_2","LM voxel count"], 9807)
self.assertEqual( segStatLogic.statistics["Test_4","GS voxel count"], 380)
self.delayDisplay("Export results to table")
resultsTableNode = slicer.vtkMRMLTableNode()
slicer.mrmlScene.AddNode(resultsTableNode)
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
self.delayDisplay("Export results to string")
logging.info(segStatLogic.exportToString())
outputFilename = slicer.app.temporaryPath + '/SegmentStatisticsTestOutput.csv'
self.delayDisplay("Export results to CSV file: "+outputFilename)
segStatLogic.exportToCSVFile(outputFilename)
self.delayDisplay('test_SegmentStatisticsBasic passed!')
示例2: exportToTable
def exportToTable(self, table=None, nonEmptyKeysOnly=True):
if not table:
table = slicer.vtkMRMLTableNode()
table.SetName(slicer.mrmlScene.GenerateUniqueName(self.grayscaleNode.GetName() + ' statistics'))
slicer.mrmlScene.AddNode(table)
table.SetUseColumnNameAsColumnHeader(True)
SegmentStatisticsLogic.exportToTable(self, table, nonEmptyKeysOnly)
return table
示例3: __init__
def __init__(self,parent=None, parameterNode=None, pluginName=None):
super(qt.QDialog,self).__init__(parent)
self.title = "Edit Segment Statistics Parameters"
self.parameterNode = parameterNode
self.pluginName = pluginName
self.logic = SegmentStatisticsLogic() # for access to plugins and editor widgets
self.logic.setParameterNode(self.parameterNode)
self.setup()
示例4: test_ScriptedSegmentEditorEffectModuleTemplate1
def test_ScriptedSegmentEditorEffectModuleTemplate1(self):
"""
Basic automated test of the segmentation method:
- Create segmentation by placing sphere-shaped seeds
- Run segmentation
- Verify results using segment statistics
The test can be executed from SelfTests module (test name: SegmentEditorScriptedSegmentEditorEffectModuleTemplate)
"""
self.delayDisplay("Starting test_ScriptedSegmentEditorEffectModuleTemplate1")
import vtkSegmentationCorePython as vtkSegmentationCore
import vtkSlicerSegmentationsModuleLogicPython as vtkSlicerSegmentationsModuleLogic
import SampleData
from SegmentStatistics import SegmentStatisticsLogic
##################################
self.delayDisplay("Load master volume")
import SampleData
sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1()
##################################
self.delayDisplay("Create segmentation containing a few spheres")
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes()
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
# Segments are defined by a list of: name and a list of sphere [radius, posX, posY, posZ]
segmentGeometries = [
['Tumor', [[10, -6,30,28]]],
['Background', [[10, 0,65,22], [15, 1, -14, 30], [12, 0, 28, -7], [5, 0,30,54], [12, 31, 33, 27], [17, -42, 30, 27], [6, -2,-17,71]]],
['Air', [[10, 76,73,0], [15, -70,74,0]]] ]
for segmentGeometry in segmentGeometries:
segmentName = segmentGeometry[0]
appender = vtk.vtkAppendPolyData()
for sphere in segmentGeometry[1]:
sphereSource = vtk.vtkSphereSource()
sphereSource.SetRadius(sphere[0])
sphereSource.SetCenter(sphere[1], sphere[2], sphere[3])
appender.AddInputConnection(sphereSource.GetOutputPort())
segment = vtkSegmentationCore.vtkSegment()
segment.SetName(segmentationNode.GetSegmentation().GenerateUniqueSegmentID(segmentName))
appender.Update()
segment.AddRepresentation(vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationClosedSurfaceRepresentationName(), appender.GetOutput())
segmentationNode.GetSegmentation().AddSegment(segment)
##################################
self.delayDisplay("Create segment editor")
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.show()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
slicer.mrmlScene.AddNode(segmentEditorNode)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setMasterVolumeNode(masterVolumeNode)
##################################
self.delayDisplay("Run segmentation")
segmentEditorWidget.setActiveEffectByName("ScriptedSegmentEditorEffectModuleTemplate")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("ObjectScaleMm", 3.0)
effect.self().onApply()
##################################
self.delayDisplay("Make segmentation results nicely visible in 3D")
segmentationDisplayNode = segmentationNode.GetDisplayNode()
segmentationDisplayNode.SetSegmentVisibility("Air", False)
segmentationDisplayNode.SetSegmentOpacity3D("Background",0.5)
##################################
self.delayDisplay("Compute statistics")
segStatLogic = SegmentStatisticsLogic()
segStatLogic.computeStatistics(segmentationNode, masterVolumeNode)
# Export results to table (just to see all results)
resultsTableNode = slicer.vtkMRMLTableNode()
slicer.mrmlScene.AddNode(resultsTableNode)
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
self.delayDisplay("Check a few numerical results")
self.assertEqual( round(segStatLogic.statistics["Tumor","LM volume cc"]), 16)
self.assertEqual( round(segStatLogic.statistics["Background","LM volume cc"]), 3010)
self.delayDisplay('test_ScriptedSegmentEditorEffectModuleTemplate1 passed')
示例5: test_SegmentStatisticsPlugins
def test_SegmentStatisticsPlugins(self):
"""
This tests some aspects of the segment statistics plugins
"""
self.delayDisplay("Starting test_SegmentStatisticsPlugins")
import vtkSegmentationCorePython as vtkSegmentationCore
import SampleData
from SegmentStatistics import SegmentStatisticsLogic
self.delayDisplay("Load master volume")
masterVolumeNode = SampleData.downloadSample('MRBrainTumor1')
self.delayDisplay("Create segmentation containing a few spheres")
segmentationNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSegmentationNode')
segmentationNode.CreateDefaultDisplayNodes()
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
# Geometry for each segment is defined by: radius, posX, posY, posZ
segmentGeometries = [[10, -6,30,28], [20, 0,65,32], [15, 1, -14, 30], [12, 0, 28, -7], [5, 0,30,64],
[12, 31, 33, 27], [17, -42, 30, 27]]
for segmentGeometry in segmentGeometries:
sphereSource = vtk.vtkSphereSource()
sphereSource.SetRadius(segmentGeometry[0])
sphereSource.SetCenter(segmentGeometry[1], segmentGeometry[2], segmentGeometry[3])
sphereSource.Update()
segment = vtkSegmentationCore.vtkSegment()
uniqueSegmentID = segmentationNode.GetSegmentation().GenerateUniqueSegmentID("Test")
segmentationNode.AddSegmentFromClosedSurfaceRepresentation(sphereSource.GetOutput(), uniqueSegmentID)
# test calculating only measurements for selected segments
self.delayDisplay("Test calculating only measurements for individual segments")
segStatLogic = SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
segStatLogic.getParameterNode().SetParameter("ScalarVolume", masterVolumeNode.GetID())
segStatLogic.updateStatisticsForSegment('Test_2')
resultsTableNode = slicer.vtkMRMLTableNode()
slicer.mrmlScene.AddNode(resultsTableNode)
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
self.assertEqual( segStatLogic.getStatistics()["Test_2","LabelmapSegmentStatisticsPlugin.voxel_count"], 9807)
with self.assertRaises(KeyError): segStatLogic.getStatistics()["Test_4","ScalarVolumeSegmentStatisticsPlugin.voxel count"]
# assert there are no result for this segment
segStatLogic.updateStatisticsForSegment('Test_4')
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
self.assertEqual( segStatLogic.getStatistics()["Test_2","LabelmapSegmentStatisticsPlugin.voxel_count"], 9807)
self.assertEqual( segStatLogic.getStatistics()["Test_4","LabelmapSegmentStatisticsPlugin.voxel_count"], 380)
with self.assertRaises(KeyError): segStatLogic.getStatistics()["Test_5","ScalarVolumeSegmentStatisticsPlugin.voxel count"]
# assert there are no result for this segment
# calculate measurements for all segments
segStatLogic.computeStatistics()
self.assertEqual( segStatLogic.getStatistics()["Test","LabelmapSegmentStatisticsPlugin.voxel_count"], 2948)
self.assertEqual( segStatLogic.getStatistics()["Test_1","LabelmapSegmentStatisticsPlugin.voxel_count"], 23281)
# test updating measurements for segments one by one
self.delayDisplay("Update some segments in the segmentation")
segmentGeometriesNew = [[5, -6,30,28], [21, 0,65,32]]
# We add/remove representations, so we temporarily block segment modifications
# to make sure display managers don't try to access data while it is in an
# inconsistent state.
wasModified = segmentationNode.StartModify()
for i in range(len(segmentGeometriesNew)):
segmentGeometry = segmentGeometriesNew[i]
sphereSource = vtk.vtkSphereSource()
sphereSource.SetRadius(segmentGeometry[0])
sphereSource.SetCenter(segmentGeometry[1], segmentGeometry[2], segmentGeometry[3])
sphereSource.Update()
segment = segmentationNode.GetSegmentation().GetNthSegment(i)
segment.RemoveAllRepresentations()
closedSurfaceName = vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationClosedSurfaceRepresentationName()
segment.AddRepresentation(closedSurfaceName,
sphereSource.GetOutput())
segmentationNode.EndModify(wasModified)
self.assertEqual( segStatLogic.getStatistics()["Test","LabelmapSegmentStatisticsPlugin.voxel_count"], 2948)
self.assertEqual( segStatLogic.getStatistics()["Test_1","LabelmapSegmentStatisticsPlugin.voxel_count"], 23281)
segStatLogic.updateStatisticsForSegment('Test_1')
self.assertEqual( segStatLogic.getStatistics()["Test","LabelmapSegmentStatisticsPlugin.voxel_count"], 2948)
self.assertTrue( segStatLogic.getStatistics()["Test_1","LabelmapSegmentStatisticsPlugin.voxel_count"]!=23281)
segStatLogic.updateStatisticsForSegment('Test')
self.assertTrue( segStatLogic.getStatistics()["Test","LabelmapSegmentStatisticsPlugin.voxel_count"]!=2948)
self.assertTrue( segStatLogic.getStatistics()["Test_1","LabelmapSegmentStatisticsPlugin.voxel_count"]!=23281)
# test enabling/disabling of individual measurements
self.delayDisplay("Test disabling of individual measurements")
segStatLogic = SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
segStatLogic.getParameterNode().SetParameter("ScalarVolume", masterVolumeNode.GetID())
segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.voxel_count.enabled",str(False))
segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.volume_cm3.enabled",str(False))
segStatLogic.computeStatistics()
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
columnHeaders = [resultsTableNode.GetColumnName(i) for i in range(resultsTableNode.GetNumberOfColumns())]
self.assertFalse('Number of voxels [voxels] (1)' in columnHeaders)
self.assertTrue('Volume [mm3] (1)' in columnHeaders)
#.........这里部分代码省略.........
示例6: setup
def setup(self):
ScriptedLoadableModuleWidget.setup(self)
self.logic = SegmentStatisticsLogic()
self.grayscaleNode = None
self.labelNode = None
self.parameterNode = None
self.parameterNodeObserver = None
# Instantiate and connect widgets ...
#
# Parameter set selector
self.parameterNodeSelector = slicer.qMRMLNodeComboBox()
self.parameterNodeSelector.nodeTypes = ["vtkMRMLScriptedModuleNode"]
self.parameterNodeSelector.addAttribute( "vtkMRMLScriptedModuleNode", "ModuleName", "SegmentStatistics" )
self.parameterNodeSelector.selectNodeUponCreation = True
self.parameterNodeSelector.addEnabled = True
self.parameterNodeSelector.renameEnabled = True
self.parameterNodeSelector.removeEnabled = True
self.parameterNodeSelector.noneEnabled = False
self.parameterNodeSelector.showHidden = True
self.parameterNodeSelector.showChildNodeTypes = False
self.parameterNodeSelector.baseName = "SegmentStatistics"
self.parameterNodeSelector.setMRMLScene( slicer.mrmlScene )
self.parameterNodeSelector.setToolTip( "Pick parameter set" )
self.layout.addWidget(self.parameterNodeSelector)
# Inputs
inputsCollapsibleButton = ctk.ctkCollapsibleButton()
inputsCollapsibleButton.text = "Inputs"
self.layout.addWidget(inputsCollapsibleButton)
inputsFormLayout = qt.QFormLayout(inputsCollapsibleButton)
# Segmentation selector
self.segmentationSelector = slicer.qMRMLNodeComboBox()
self.segmentationSelector.nodeTypes = ["vtkMRMLSegmentationNode"]
self.segmentationSelector.addEnabled = False
self.segmentationSelector.removeEnabled = True
self.segmentationSelector.renameEnabled = True
self.segmentationSelector.setMRMLScene( slicer.mrmlScene )
self.segmentationSelector.setToolTip( "Pick the segmentation to compute statistics for" )
inputsFormLayout.addRow("Segmentation:", self.segmentationSelector)
# Scalar volume selector
self.scalarSelector = slicer.qMRMLNodeComboBox()
self.scalarSelector.nodeTypes = ["vtkMRMLScalarVolumeNode"]
self.scalarSelector.addEnabled = False
self.scalarSelector.removeEnabled = True
self.scalarSelector.renameEnabled = True
self.scalarSelector.noneEnabled = True
self.scalarSelector.showChildNodeTypes = False
self.scalarSelector.setMRMLScene( slicer.mrmlScene )
self.scalarSelector.setToolTip( "Select the scalar volume for intensity statistics calculations")
inputsFormLayout.addRow("Scalar volume:", self.scalarSelector)
# Output table selector
outputCollapsibleButton = ctk.ctkCollapsibleButton()
outputCollapsibleButton.text = "Output"
self.layout.addWidget(outputCollapsibleButton)
outputFormLayout = qt.QFormLayout(outputCollapsibleButton)
self.outputTableSelector = slicer.qMRMLNodeComboBox()
self.outputTableSelector.noneDisplay = "Create new table"
self.outputTableSelector.setMRMLScene(slicer.mrmlScene)
self.outputTableSelector.nodeTypes = ["vtkMRMLTableNode"]
self.outputTableSelector.addEnabled = True
self.outputTableSelector.selectNodeUponCreation = True
self.outputTableSelector.renameEnabled = True
self.outputTableSelector.removeEnabled = True
self.outputTableSelector.noneEnabled = True
self.outputTableSelector.setToolTip("Select the table where statistics will be saved into")
self.outputTableSelector.setCurrentNode(None)
outputFormLayout.addRow("Output table:", self.outputTableSelector)
# Parameter set
parametersCollapsibleButton = ctk.ctkCollapsibleButton()
parametersCollapsibleButton.text = "Advanced"
parametersCollapsibleButton.collapsed = True
self.layout.addWidget(parametersCollapsibleButton)
self.parametersLayout = qt.QFormLayout(parametersCollapsibleButton)
# Edit parameter set button to open SegmentStatisticsParameterEditorDialog
# Note: we add the plugins' option widgets to the module widget instead of using the editor dialog
#self.editParametersButton = qt.QPushButton("Edit Parameter Set")
#self.editParametersButton.toolTip = "Editor Statistics Plugin Parameter Set."
#self.parametersLayout.addRow(self.editParametersButton)
#self.editParametersButton.connect('clicked()', self.onEditParameters)
# add caclulator's option widgets
self.addPluginOptionWidgets()
# Apply Button
self.applyButton = qt.QPushButton("Apply")
self.applyButton.toolTip = "Calculate Statistics."
self.applyButton.enabled = False
self.parent.layout().addWidget(self.applyButton)
# Add vertical spacer
self.parent.layout().addStretch(1)
#.........这里部分代码省略.........
示例7: SegmentStatisticsWidget
class SegmentStatisticsWidget(ScriptedLoadableModuleWidget):
"""Uses ScriptedLoadableModuleWidget base class, available at:
https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
"""
def setup(self):
ScriptedLoadableModuleWidget.setup(self)
self.logic = SegmentStatisticsLogic()
self.grayscaleNode = None
self.labelNode = None
self.parameterNode = None
self.parameterNodeObserver = None
# Instantiate and connect widgets ...
#
# Parameter set selector
self.parameterNodeSelector = slicer.qMRMLNodeComboBox()
self.parameterNodeSelector.nodeTypes = ["vtkMRMLScriptedModuleNode"]
self.parameterNodeSelector.addAttribute( "vtkMRMLScriptedModuleNode", "ModuleName", "SegmentStatistics" )
self.parameterNodeSelector.selectNodeUponCreation = True
self.parameterNodeSelector.addEnabled = True
self.parameterNodeSelector.renameEnabled = True
self.parameterNodeSelector.removeEnabled = True
self.parameterNodeSelector.noneEnabled = False
self.parameterNodeSelector.showHidden = True
self.parameterNodeSelector.showChildNodeTypes = False
self.parameterNodeSelector.baseName = "SegmentStatistics"
self.parameterNodeSelector.setMRMLScene( slicer.mrmlScene )
self.parameterNodeSelector.setToolTip( "Pick parameter set" )
self.layout.addWidget(self.parameterNodeSelector)
# Inputs
inputsCollapsibleButton = ctk.ctkCollapsibleButton()
inputsCollapsibleButton.text = "Inputs"
self.layout.addWidget(inputsCollapsibleButton)
inputsFormLayout = qt.QFormLayout(inputsCollapsibleButton)
# Segmentation selector
self.segmentationSelector = slicer.qMRMLNodeComboBox()
self.segmentationSelector.nodeTypes = ["vtkMRMLSegmentationNode"]
self.segmentationSelector.addEnabled = False
self.segmentationSelector.removeEnabled = True
self.segmentationSelector.renameEnabled = True
self.segmentationSelector.setMRMLScene( slicer.mrmlScene )
self.segmentationSelector.setToolTip( "Pick the segmentation to compute statistics for" )
inputsFormLayout.addRow("Segmentation:", self.segmentationSelector)
# Scalar volume selector
self.scalarSelector = slicer.qMRMLNodeComboBox()
self.scalarSelector.nodeTypes = ["vtkMRMLScalarVolumeNode"]
self.scalarSelector.addEnabled = False
self.scalarSelector.removeEnabled = True
self.scalarSelector.renameEnabled = True
self.scalarSelector.noneEnabled = True
self.scalarSelector.showChildNodeTypes = False
self.scalarSelector.setMRMLScene( slicer.mrmlScene )
self.scalarSelector.setToolTip( "Select the scalar volume for intensity statistics calculations")
inputsFormLayout.addRow("Scalar volume:", self.scalarSelector)
# Output table selector
outputCollapsibleButton = ctk.ctkCollapsibleButton()
outputCollapsibleButton.text = "Output"
self.layout.addWidget(outputCollapsibleButton)
outputFormLayout = qt.QFormLayout(outputCollapsibleButton)
self.outputTableSelector = slicer.qMRMLNodeComboBox()
self.outputTableSelector.noneDisplay = "Create new table"
self.outputTableSelector.setMRMLScene(slicer.mrmlScene)
self.outputTableSelector.nodeTypes = ["vtkMRMLTableNode"]
self.outputTableSelector.addEnabled = True
self.outputTableSelector.selectNodeUponCreation = True
self.outputTableSelector.renameEnabled = True
self.outputTableSelector.removeEnabled = True
self.outputTableSelector.noneEnabled = True
self.outputTableSelector.setToolTip("Select the table where statistics will be saved into")
self.outputTableSelector.setCurrentNode(None)
outputFormLayout.addRow("Output table:", self.outputTableSelector)
# Parameter set
parametersCollapsibleButton = ctk.ctkCollapsibleButton()
parametersCollapsibleButton.text = "Advanced"
parametersCollapsibleButton.collapsed = True
self.layout.addWidget(parametersCollapsibleButton)
self.parametersLayout = qt.QFormLayout(parametersCollapsibleButton)
# Edit parameter set button to open SegmentStatisticsParameterEditorDialog
# Note: we add the plugins' option widgets to the module widget instead of using the editor dialog
#self.editParametersButton = qt.QPushButton("Edit Parameter Set")
#self.editParametersButton.toolTip = "Editor Statistics Plugin Parameter Set."
#self.parametersLayout.addRow(self.editParametersButton)
#self.editParametersButton.connect('clicked()', self.onEditParameters)
# add caclulator's option widgets
self.addPluginOptionWidgets()
# Apply Button
self.applyButton = qt.QPushButton("Apply")
self.applyButton.toolTip = "Calculate Statistics."
#.........这里部分代码省略.........
示例8: SegmentStatisticsParameterEditorDialog
class SegmentStatisticsParameterEditorDialog(qt.QDialog):
"""Dialog to edit parameters of segment statistics plugins.
Most users will only need to call the static method editParameters(...)
"""
@staticmethod
def editParameters(parameterNode, pluginName=None):
"""Executes a modal dialog to edit a segment statistics parameter node if a pluginName is specified, only
options for this plugin are displayed"
"""
dialog = SegmentStatisticsParameterEditorDialog(parent=None, parameterNode=parameterNode,
pluginName=pluginName)
return dialog.exec_()
def __init__(self,parent=None, parameterNode=None, pluginName=None):
super(qt.QDialog,self).__init__(parent)
self.title = "Edit Segment Statistics Parameters"
self.parameterNode = parameterNode
self.pluginName = pluginName
self.logic = SegmentStatisticsLogic() # for access to plugins and editor widgets
self.logic.setParameterNode(self.parameterNode)
self.setup()
def setParameterNode(self, parameterNode):
"""Set the parameter node the dialog will operate on"""
if parameterNode==self.parameterNode:
return
self.parameterNode = parameterNode
self.logic.setParameterNode(self.parameterNode)
def setup(self):
self.setLayout(qt.QVBoxLayout())
self.descriptionLabel = qt.QLabel("Edit segment statistics plugin parameters:",0)
self.doneButton = qt.QPushButton("Done")
self.doneButton.toolTip = "Finish editing."
doneWidget = qt.QWidget(self)
doneWidget.setLayout(qt.QHBoxLayout())
doneWidget.layout().addStretch(1)
doneWidget.layout().addWidget(self.doneButton, 0)
parametersScrollArea = qt.QScrollArea(self)
self.parametersWidget = qt.QWidget(parametersScrollArea)
self.parametersLayout = qt.QFormLayout(self.parametersWidget)
self._addPluginOptionWidgets()
parametersScrollArea.setWidget(self.parametersWidget)
parametersScrollArea.widgetResizable = True
parametersScrollArea.setVerticalScrollBarPolicy(qt.Qt.ScrollBarAsNeeded )
parametersScrollArea.setHorizontalScrollBarPolicy(qt.Qt.ScrollBarAsNeeded)
self.layout().addWidget(self.descriptionLabel,0)
self.layout().addWidget(parametersScrollArea, 1)
self.layout().addWidget(doneWidget, 0)
self.doneButton.connect('clicked()', lambda: self.done(1))
def _addPluginOptionWidgets(self):
description = "Edit segment statistics plugin parameters:"
if self.pluginName:
description = "Edit "+self.pluginName+" plugin parameters:"
self.descriptionLabel.text = description
if self.pluginName:
for plugin in self.logic.plugins:
if plugin.name==self.pluginName:
self.parametersLayout.addRow(plugin.optionsWidget)
else:
for plugin in self.logic.plugins:
pluginOptionsCollapsibleButton = ctk.ctkCollapsibleGroupBox(self.parametersWidget)
pluginOptionsCollapsibleButton.setTitle( plugin.name )
pluginOptionsFormLayout = qt.QFormLayout(pluginOptionsCollapsibleButton)
pluginOptionsFormLayout.addRow(plugin.optionsWidget)
self.parametersLayout.addRow(pluginOptionsCollapsibleButton)
示例9: __init__
def __init__(self):
SegmentStatisticsLogic.__init__(self)
self.plugins = [p for p in self.plugins if not isinstance(p,LabelmapSegmentStatisticsPlugin)]
self.reset()
self.terminologyLogic = slicer.modules.terminologies.logic()
示例10: setup
def setup(self):
ScriptedLoadableModuleWidget.setup(self)
self.logic = SegmentStatisticsLogic()
self.grayscaleNode = None
self.labelNode = None
self.fileName = None
self.fileDialog = None
# Instantiate and connect widgets ...
#
# Inputs
inputsCollapsibleButton = ctk.ctkCollapsibleButton()
inputsCollapsibleButton.text = "Inputs"
self.layout.addWidget(inputsCollapsibleButton)
inputsFormLayout = qt.QFormLayout(inputsCollapsibleButton)
# Segmentation selector
self.segmentationSelector = slicer.qMRMLNodeComboBox()
self.segmentationSelector.nodeTypes = ["vtkMRMLSegmentationNode"]
self.segmentationSelector.addEnabled = False
self.segmentationSelector.removeEnabled = True
self.segmentationSelector.renameEnabled = True
self.segmentationSelector.setMRMLScene( slicer.mrmlScene )
self.segmentationSelector.setToolTip( "Pick the segmentation to compute statistics for" )
inputsFormLayout.addRow("Segmentation:", self.segmentationSelector)
# Grayscale volume selector
self.grayscaleSelector = slicer.qMRMLNodeComboBox()
self.grayscaleSelector.nodeTypes = ["vtkMRMLScalarVolumeNode"]
self.grayscaleSelector.addEnabled = False
self.grayscaleSelector.removeEnabled = True
self.grayscaleSelector.renameEnabled = True
self.grayscaleSelector.noneEnabled = True
self.grayscaleSelector.showChildNodeTypes = False
self.grayscaleSelector.setMRMLScene( slicer.mrmlScene )
self.grayscaleSelector.setToolTip( "Select the grayscale volume for intensity statistics calculations")
inputsFormLayout.addRow("Grayscale volume:", self.grayscaleSelector)
# Output table selector
outputCollapsibleButton = ctk.ctkCollapsibleButton()
outputCollapsibleButton.text = "Output"
self.layout.addWidget(outputCollapsibleButton)
outputFormLayout = qt.QFormLayout(outputCollapsibleButton)
self.outputTableSelector = slicer.qMRMLNodeComboBox()
self.outputTableSelector.nodeTypes = ["vtkMRMLTableNode"]
self.outputTableSelector.addEnabled = True
self.outputTableSelector.selectNodeUponCreation = True
self.outputTableSelector.renameEnabled = True
self.outputTableSelector.removeEnabled = True
self.outputTableSelector.noneEnabled = False
self.outputTableSelector.setMRMLScene( slicer.mrmlScene )
self.outputTableSelector.setToolTip( "Select the table where statistics will be saved into")
outputFormLayout.addRow("Output table:", self.outputTableSelector)
# Apply Button
self.applyButton = qt.QPushButton("Apply")
self.applyButton.toolTip = "Calculate Statistics."
self.applyButton.enabled = False
self.parent.layout().addWidget(self.applyButton)
# Add vertical spacer
self.parent.layout().addStretch(1)
# connections
self.applyButton.connect('clicked()', self.onApply)
self.grayscaleSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onNodeSelectionChanged)
self.segmentationSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onNodeSelectionChanged)
self.outputTableSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onNodeSelectionChanged)
self.onNodeSelectionChanged()
示例11: SegmentStatisticsWidget
class SegmentStatisticsWidget(ScriptedLoadableModuleWidget):
"""Uses ScriptedLoadableModuleWidget base class, available at:
https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
"""
def setup(self):
ScriptedLoadableModuleWidget.setup(self)
self.logic = SegmentStatisticsLogic()
self.grayscaleNode = None
self.labelNode = None
self.fileName = None
self.fileDialog = None
# Instantiate and connect widgets ...
#
# Inputs
inputsCollapsibleButton = ctk.ctkCollapsibleButton()
inputsCollapsibleButton.text = "Inputs"
self.layout.addWidget(inputsCollapsibleButton)
inputsFormLayout = qt.QFormLayout(inputsCollapsibleButton)
# Segmentation selector
self.segmentationSelector = slicer.qMRMLNodeComboBox()
self.segmentationSelector.nodeTypes = ["vtkMRMLSegmentationNode"]
self.segmentationSelector.addEnabled = False
self.segmentationSelector.removeEnabled = True
self.segmentationSelector.renameEnabled = True
self.segmentationSelector.setMRMLScene( slicer.mrmlScene )
self.segmentationSelector.setToolTip( "Pick the segmentation to compute statistics for" )
inputsFormLayout.addRow("Segmentation:", self.segmentationSelector)
# Grayscale volume selector
self.grayscaleSelector = slicer.qMRMLNodeComboBox()
self.grayscaleSelector.nodeTypes = ["vtkMRMLScalarVolumeNode"]
self.grayscaleSelector.addEnabled = False
self.grayscaleSelector.removeEnabled = True
self.grayscaleSelector.renameEnabled = True
self.grayscaleSelector.noneEnabled = True
self.grayscaleSelector.showChildNodeTypes = False
self.grayscaleSelector.setMRMLScene( slicer.mrmlScene )
self.grayscaleSelector.setToolTip( "Select the grayscale volume for intensity statistics calculations")
inputsFormLayout.addRow("Grayscale volume:", self.grayscaleSelector)
# Output table selector
outputCollapsibleButton = ctk.ctkCollapsibleButton()
outputCollapsibleButton.text = "Output"
self.layout.addWidget(outputCollapsibleButton)
outputFormLayout = qt.QFormLayout(outputCollapsibleButton)
self.outputTableSelector = slicer.qMRMLNodeComboBox()
self.outputTableSelector.nodeTypes = ["vtkMRMLTableNode"]
self.outputTableSelector.addEnabled = True
self.outputTableSelector.selectNodeUponCreation = True
self.outputTableSelector.renameEnabled = True
self.outputTableSelector.removeEnabled = True
self.outputTableSelector.noneEnabled = False
self.outputTableSelector.setMRMLScene( slicer.mrmlScene )
self.outputTableSelector.setToolTip( "Select the table where statistics will be saved into")
outputFormLayout.addRow("Output table:", self.outputTableSelector)
# Apply Button
self.applyButton = qt.QPushButton("Apply")
self.applyButton.toolTip = "Calculate Statistics."
self.applyButton.enabled = False
self.parent.layout().addWidget(self.applyButton)
# Add vertical spacer
self.parent.layout().addStretch(1)
# connections
self.applyButton.connect('clicked()', self.onApply)
self.grayscaleSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onNodeSelectionChanged)
self.segmentationSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onNodeSelectionChanged)
self.outputTableSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onNodeSelectionChanged)
self.onNodeSelectionChanged()
def onNodeSelectionChanged(self):
self.applyButton.enabled = (self.segmentationSelector.currentNode() is not None) and (self.outputTableSelector.currentNode() is not None)
if self.segmentationSelector.currentNode():
self.outputTableSelector.baseName = self.segmentationSelector.currentNode().GetName() + ' statistics'
def onApply(self):
"""Calculate the label statistics
"""
# Lock GUI
self.applyButton.text = "Working..."
self.applyButton.setEnabled(False)
slicer.app.processEvents()
# Compute statistics
self.logic.computeStatistics(self.segmentationSelector.currentNode(), self.grayscaleSelector.currentNode())
self.logic.exportToTable(self.outputTableSelector.currentNode())
# Unlock GUI
self.applyButton.setEnabled(True)
self.applyButton.text = "Apply"
self.logic.showTable(self.outputTableSelector.currentNode())