'NoneType' Object has no attribute 'GetParentTransformNode'?

I’m not really sure what happened… my code was working well yesterday and this morning I can’t figure out what changed.

My goal is to iterate through all the segmentation files in a directory and use the Segment Statistics module to get the segment volumes for each one. All my segmentation files are saved as “study_id_number_segmentations.seg.nrrd” and the corresponding volumes are saved as “study_id_number_MRI.nii”, where each study_id_number refers to a particular patient. So far I have:

Setup imports

import os
import glob
from path lib import Path
import SegmentStatistics

Load a specific segmentation and corresponding Node

segmentation_file = “path/to/study_id_1_segmentations.seg.nrrd”
segmentationNode = getNode(“study_id_1_segmentations”)

Compute segment statistics for that segmentation

segStatLogic = SegmentStatistics.SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter(“study_id_1_segmentations”, segmentationNode.GetID())
stats = segStatLogic.getStatistics()

I’m (seemingly) able to load the volume and the node, but when I try to compute segment statistics I get the error: ‘NoneType’ object has no attribute ‘GetParentTransformNode’. Am I missing something here?

Just a very quick observation: The line:

segStatLogic.getParameterNode().SetParameter(“study_id_1_segmentations”, segmentationNode.GetID())

Looks a bit wrong. I think it should be:

segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())

Also if you want statistics like mean pixel values etc which come from the volume, you should also point segment statistics toward the correct volume:

segStatLogic.getParameterNode().SetParameter("ScalarVolume", volumeNode.GetID())

You would first need to load the volume though and assign it to the variable ‘volumeNode’

1 Like

That works, thanks for the correction!