Hello! I a healthcare researcher working on medical image segmentation. I am hoping to automate the retrieval of SegmentationStatistics tables using 3D Slicer’s Python API. However, when I was developing my program, I ran into an issue with the code below.
volume_path = os.path.join(input_directory, filename, f'{filename}.nrrd')
segmentation_path = os.path.join(input_directory, filename, f'{filename}_corrected.seg.nrrd')
volume_node = slicer.util.loadVolume(volume_path)
segmentation_node = slicer.util.loadSegmentation(segmentation_path)
segmentStatisticsLogic = SegmentStatistics.SegmentStatisticsLogic()
segmentStatisticsLogic.getParameterNode().SetNodeReferenceID("Segmentation", segmentation_node.GetID())
segmentStatisticsLogic.getParameterNode().SetNodeReferenceID("ScalarVolume", volume_node.GetID())
segmentStatisticsLogic.computeStatistics()
When I run the above, the final line of code throws an Attribute Error
(AttributeError: ‘NoneType’ object has no attribute ‘GetParentTransformNode’). I looked into the API source code to try to find the root of the error and found that the error comes from the beginning of the computeStatistics method.
def computeStatistics(self):
"""Compute statistical measures for all (visible) segments"""
self.reset()
segmentationNode = slicer.mrmlScene.GetNodeByID(self.getParameterNode().GetParameter("Segmentation"))
transformedSegmentationNode = None
try:
if not segmentationNode.GetParentTransformNode() is None:
...
It seems that the segmentationNode is None, but I am not sure why. Is there an error with the way that I loaded the files? Or is there something else I am not considering?
I am new to 3D Slicer (and segmentation, at large) so any insight into this would be a huge help! Thank you very much in advance for your time and consideration and take care.