Load the source CT series as a list of pydicom Dataset objects and extract the per-frame spatial metadata needed for the SEG Frame of Reference
Create a SegmentDescription for each segment class, specifying SegmentLabel, SegmentAlgorithmType (AUTOMATIC for fully AI-generated masks), and an anatomic region coded concept
Build pixel arrays as boolean (BINARY segmentation type) or float32 (FRACTIONAL type for probability maps) numpy arrays with shape matching the source image grid
Construct the Segmentation object with highdicom.seg.Segmentation(source_images=ct_datasets, pixel_array=mask_array, segmentation_type=SEG_TYPE, segment_descriptions=[...], series_instance_uid=generate_uid(), sop_instance_uid=generate_uid())
Store the resulting DICOM SEG file to the same study via STOW-RS so PACS and viewers can display it in context with the source images
Known gotchas
BINARY segmentation pixel data is bit-packed in DICOM SEG — one bit per pixel — whereas FRACTIONAL type stores 8-bit scaled values; do not pass a uint8 array expecting binary interpretation without setting the segmentation type correctly
The PixelSpacing, ImageOrientationPatient, and ImagePositionPatient of each SEG frame must exactly match the corresponding source image frame; any spatial mismatch causes viewer registration errors
Some PACS systems have limited SEG rendering support; verify viewer capability before relying on SEG for clinical communication — DICOM SR with spatial coordinates may be a more widely supported alternative for annotations
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp