diff --git a/DICOMPlugins/DICOMSegmentationPlugin.py b/DICOMPlugins/DICOMSegmentationPlugin.py index 4b3c109..68946e4 100644 --- a/DICOMPlugins/DICOMSegmentationPlugin.py +++ b/DICOMPlugins/DICOMSegmentationPlugin.py @@ -251,24 +251,26 @@ def _importSegmentAndRemoveLabel(self, segmentLabelNode, segmentationNode): if segmentation.GetNumberOfSegments() == 0: logging.warning("Empty segment loaded from DICOM SEG!") + thisLabelSegmentID = 0 for segmentId in range(numberOfSegmentsBeforeImport, segmentation.GetNumberOfSegments()): logging.info(f"Setting attributes for segment {segmentId} ...") segment = segmentation.GetNthSegment(segmentId) - segment.SetName(segmentLabelNode.labelAttributes[segmentId]["Name"]) - segment.SetNameAutoGenerated(segmentLabelNode.labelAttributes[segmentId]["NameAutoGenerated"]) - segment.SetTag("Description", segmentLabelNode.labelAttributes[segmentId]["Description"]) - segment.SetColor([float(segmentLabelNode.labelAttributes[segmentId]["ColorR"]), - float(segmentLabelNode.labelAttributes[segmentId]["ColorG"]), - float(segmentLabelNode.labelAttributes[segmentId]["ColorB"])]) + segment.SetName(segmentLabelNode.labelAttributes[thisLabelSegmentID]["Name"]) + segment.SetNameAutoGenerated(segmentLabelNode.labelAttributes[thisLabelSegmentID]["NameAutoGenerated"]) + segment.SetTag("Description", segmentLabelNode.labelAttributes[thisLabelSegmentID]["Description"]) + segment.SetColor([float(segmentLabelNode.labelAttributes[thisLabelSegmentID]["ColorR"]), + float(segmentLabelNode.labelAttributes[thisLabelSegmentID]["ColorG"]), + float(segmentLabelNode.labelAttributes[thisLabelSegmentID]["ColorB"])]) segment.SetTag(vtkSegmentationCore.vtkSegment.GetTerminologyEntryTagName(), - segmentLabelNode.labelAttributes[segmentId]["Terminology"]) - algorithmName = segmentLabelNode.labelAttributes[segmentId]["DICOM.SegmentAlgorithmName"] + segmentLabelNode.labelAttributes[thisLabelSegmentID]["Terminology"]) + algorithmName = segmentLabelNode.labelAttributes[thisLabelSegmentID]["DICOM.SegmentAlgorithmName"] if algorithmName is not None: segment.SetTag("DICOM.SegmentAlgorithmName", algorithmName) - algorithmType = segmentLabelNode.labelAttributes[segmentId]["DICOM.SegmentAlgorithmType"] + algorithmType = segmentLabelNode.labelAttributes[thisLabelSegmentID]["DICOM.SegmentAlgorithmType"] if algorithmType is not None: segment.SetTag("DICOM.SegmentAlgorithmType", algorithmType) + thisLabelSegmentID += 1 self._removeLabelNode(segmentLabelNode)