I am using this script to determine the volume and surface area of my segments.
segmentationNode = getNode("Segmentation")
# Compute segment statistics
import SegmentStatistics
segStatLogic = SegmentStatistics.SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
segStatLogic.computeStatistics()
stats = segStatLogic.getStatistics()
# Display volume and surface area of each segment
for segmentId in stats["SegmentIDs"]:
volume_mm3 = stats[segmentId,"LabelmapSegmentStatisticsPlugin.volume_mm3"]
surface_mm2 = stats[segmentId, "ClosedSurfaceSegmentStatisticsPlugin.surface_mm2"]
segmentName = segmentationNode.GetSegmentation().GetSegment(segmentId).GetName()
print(f"{segmentName} volume = {volume_mm3} mm3")
print(f"{segmentName} volume = {surface_mm2} mm2")
The script works fine when the segments are displayed in 3D, but it works only for the volume when the 3D view is off.
When I have too large or complex volume/segments, I cannot display them in 3D because I get this error:
“Slicer has caught an application error, please save your work and restart.\n\nThe application has run out of memory. Increasing virtual memory size in system settings or adding more RAM may fix this issue.\n\nIf you have a repeatable sequence of steps that causes this message, please report the issue following instructions available at https://slicer.org\n\n\nThe message detail is:\n\nException thrown in event: bad array new length”
I guess the files are too complex for my computer and there is not much I can do about it. Although it is strange because this computer has 192 GB of RAM.
Is there another way to determinate the surface of the segments avoiding 3D visualization?