本文整理汇总了Python中SegmentStatistics.SegmentStatisticsLogic.getStatistics方法的典型用法代码示例。如果您正苦于以下问题:Python SegmentStatisticsLogic.getStatistics方法的具体用法?Python SegmentStatisticsLogic.getStatistics怎么用?Python SegmentStatisticsLogic.getStatistics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SegmentStatistics.SegmentStatisticsLogic
的用法示例。
在下文中一共展示了SegmentStatisticsLogic.getStatistics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_SegmentStatisticsBasic
# 需要导入模块: from SegmentStatistics import SegmentStatisticsLogic [as 别名]
# 或者: from SegmentStatistics.SegmentStatisticsLogic import getStatistics [as 别名]
def test_SegmentStatisticsBasic(self):
"""
This tests some aspects of the label statistics
"""
self.delayDisplay("Starting test_SegmentStatisticsBasic")
import vtkSegmentationCorePython as vtkSegmentationCore
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()
uniqueSegmentID = segmentationNode.GetSegmentation().GenerateUniqueSegmentID("Test")
segmentationNode.AddSegmentFromClosedSurfaceRepresentation(sphereSource.GetOutput(), uniqueSegmentID)
self.delayDisplay("Compute statistics")
segStatLogic = SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
segStatLogic.getParameterNode().SetParameter("ScalarVolume", masterVolumeNode.GetID())
segStatLogic.computeStatistics()
self.delayDisplay("Check a few numerical results")
self.assertEqual( segStatLogic.getStatistics()["Test_2","LabelmapSegmentStatisticsPlugin.voxel_count"], 9807)
self.assertEqual( segStatLogic.getStatistics()["Test_4","ScalarVolumeSegmentStatisticsPlugin.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: test_SegmentStatisticsPlugins
# 需要导入模块: from SegmentStatistics import SegmentStatisticsLogic [as 别名]
# 或者: from SegmentStatistics.SegmentStatisticsLogic import getStatistics [as 别名]
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)
#.........这里部分代码省略.........