AddSegment error

Using a local build of 5.3.0-2023-03-04 r31618 / b0b9be5 on Ubuntu 23.02 I get an error when I run the create segmentation node snippet from Programmatically Create a SegmentationNode and LabelMapNode from Polygon Coordinates:

The last line
segmentationNode.GetSegmentation().AddSegment(segment)
results in the error: [VTK] AddSegment: Unable to create master representation!

How do you create the master representation?

It is quite an old release example. Maybe now you need to set the master representation to planar contours. Or maybe you just haven’t installed SlicerRT extension.

Anyway, you can find a complete implementation for n this module that imports parallel contours from an OsiriX segmentation file that should work well:

Why do you need to create a segment from parallel contours? Are you implementing an importer for a new file format?

I was using it as an example of creating a segmentation from datapoints.

I am creating a module to process nuclear medicine dynamic images and one of the steps involves drawing a rectangular ROI to do count statistics. I currently use the scissors rectangle tool for the ROI but it would be better if the ROI could be adjusted after creation.

I want to make a box ROI in Markups and then convert it to a binary labelmap so I can run Mask Volume. The code snippet looked like it would help make the labelmap.