Apologies if this is fairly obvious, learning python has been a steep learning curve. I have a segmentation that includes two segments: blood and bone. Using the docs, I’ve been able to find code that automatically prints the volume of both:
import SegmentStatistics
segStatLogic = SegmentStatistics.SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter(“ScalarVolume”, volumeNode.GetID())
segStatLogic.getParameterNode().SetParameter(“Segmentation”, segmentationNode.GetID())
segStatLogic.computeStatistics()
stats = segStatLogic.getStatistics()
for segmentId in stats[“SegmentIDs”]:
volume_mm3 = stats[segmentId,“LabelmapSegmentStatisticsPlugin.volume_mm3”]
segmentName = segmentationNode.GetSegmentation().GetSegment(segmentId).GetName()
print(f"{segmentName} volume = {volume_mm3} mm3")
However, is there a way to return ONLY one of the segment volumes from a segmentation? For example:
stats[“SegmentIDs”][0] correponds to the blood segment, and stats[“SegmentIDs”][1] to the bone segment. Is it possible to alter the above code to get just the blood volume?