本文整理汇总了Python中SegmentStatistics.SegmentStatisticsLogic.exportToString方法的典型用法代码示例。如果您正苦于以下问题:Python SegmentStatisticsLogic.exportToString方法的具体用法?Python SegmentStatisticsLogic.exportToString怎么用?Python SegmentStatisticsLogic.exportToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SegmentStatistics.SegmentStatisticsLogic
的用法示例。
在下文中一共展示了SegmentStatisticsLogic.exportToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_SegmentStatisticsBasic
# 需要导入模块: from SegmentStatistics import SegmentStatisticsLogic [as 别名]
# 或者: from SegmentStatistics.SegmentStatisticsLogic import exportToString [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!')