Solution:
- I used LabelmapSegmentStatistics to pull the centroid for each segment in the Segmentation
- Then I used the centroid coordinates to generate new spherical segments with a 1mm diameter (or radius?)
- These can be used with Segment statistics to query core lesion locations based on anatomical atlases
# Pull Centroids and generate 1mm spheric lesions in centroid for anatomical assessment
# Adjust name for "Segmentation" and "Volume" as needed
import numpy as np
import SegmentStatistics
segmentationNode = slicer.util.getNode("Segmentation")
volume_node = slicer.util.getNode("Volume")
segmentation = segmentationNode.GetSegmentation()
segnum = segmentation.GetNumberOfSegments()
for i in range(segnum):
segment = segmentation.GetNthSegment(i)
segmentId = segmentationNode.GetSegmentation().GetSegmentIdBySegment(segment)
segmentName = segment.GetName()
segStatLogic = SegmentStatistics.SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.centroid_ras.enabled", str(True))
segStatLogic.computeStatistics()
stats = segStatLogic.getStatistics()
print(segmentName)
centroid_ras = stats[segmentId,"LabelmapSegmentStatisticsPlugin.centroid_ras"]
print(centroid_ras)
tumorCentroid = vtk.vtkSphereSource()
tumorCentroid.SetCenter(centroid_ras)
tumorCentroid.SetRadius(1)
tumorCentroid.Update()
CentroidSegmentName = segmentName + "-centroid"
segmentId = segmentationNode.AddSegmentFromClosedSurfaceRepresentation(tumorCentroid.GetOutput(), CentroidSegmentName, [1.0,0.0,0.0])