Hello,
I am working on importing numpy arrays into a segmentation so that they are shown in the segment editor as new segments.
What I have now after seeing some examples is:
label_map_volume = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
slicer.util.updateVolumeFromArray(label_map_volume, segmentation_mask)
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(label_map_volume, segmentation_node)
slicer.util.updateSegmentBinaryLabelmapFromArray(
segmentation_mask,
segmentation_node,
label_map_volume.GetName(),
self.volume_node)
slicer.mrmlScene.RemoveNode(label_map_volume)
Where segmentation_node
is the numpy array with the new segment to be added to the segmentation and self.volume_node.
The problem is that every segment adds to memory about as much as the volume size, as if the whole array is saved and shown, so after ~20 to 30 segments Slicer slows down. I considered using a single array to store all the segmentations because overlapping is not a problem, but I do not know if Slicer works more efficiently than this under the hood and this approach is not optimal. I assume this is not a memory leak because the label map node is deleted once the segmentation has been updated. What is the best option from here?
Thank you for the help.