I’m making a module where I go through the connected components in the image (by clicking previous/next) and give them a label according to the button a user has pressed. For example, the user goes through the segmentations and assigns the correct organ to the segmentation by clicking on one of the three buttons: Liver, Brain or Other.
I want to now change the name of the segmentation according to the button that they have pressed. How do I get the segment ID that the segment editor is currently on?
I know you can get an ID or name of a segment like this:
segment = self.segmentation_node.GetSegment(segment_ID)
but I don’t know the ID/name. I just want to get the ID of the current segment that is selected in the segment editor.
The currently selected segment is a property of the segment editor node, rather than the segmentation itself. Conceptually, the segmentation node holds the segmentation itself, while a segment editor node modifies the segmentation in a segmentation node. With this separation, it would be possible for a segmentation to be being modified by two independent segment editors, for example. So, what you need is the segment editor node that the user is selecting the current segment with. Then, you can get the segment ID of the currently selected segment and change its name with something like
File "C:/Users/.../CheckSeg.py", line 306, in confirm_label_clicked
currentSegment = segmentationNode.GetSegmentation().GetSegment(currentSegmentID)
AttributeError: 'NoneType' object has no attribute 'GetSegmentation'
You have created a new segment editor node, which has not been associated with a segmentation yet. Instead, what you want to do is access the segment editor node which is associated with the Slicer GUI. You can do this via
I also learned while investigating this that as an alternative path, you can get the current segment ID and segmentation node directly from the segment editor widget via: