SEG, RTSTRUCT and binary masks are not the same
Tonight · ~25 min · read · energy: low · setup: none
“A segmentation” sounds like one thing. It is three different data structures, each of which preserves and destroys different information. This lesson is what each one actually is, so that when a mask goes missing or a boundary shifts you know which representation lost it.
The anchor: the same tumour, three storage shapes
You segment a tumour and can save it as: a binary NumPy mask, a DICOM SEG, or an RTSTRUCT. They all describe “these voxels are tumour”, but they carry different geometry, different references, and different fidelity. Converting between them is lossy in different ways. Knowing those losses is what stops you from quietly corrupting a segmentation every time you change tools.
Binary label map (mask)
A 3D array the same shape as the image, where each voxel holds a label
(1 = tumour, 0 = background; optionally multi-label). This is what a deep
segmentation model outputs and what PyRadiomics consumes.
- Pro: trivially consumable; its geometry is the image’s geometry.
- Con: it has no explicit link back to the source images unless you keep it alongside the image; fractional boundary information is quantised away.
- Critical geometry requirement: the mask must share the reference image’s origin/spacing/direction. A mask that is “the same shape” but in a different physical space is a bug — the exact failure of lesson 5.
DICOM SEG (Segmentation Storage)
A first-class DICOM object. The features that make it more than a mask:
- Reference image: cites the source CT via
ReferencedSeriesSequenceand, per segment/frame,DerivationImageSequence/SourceImageSequencewith the sourceSOPInstanceUIDs. This is the source-image reference a bare mask lacks. - Per-frame geometry: each frame carries its own
ImagePositionPatient/ orientation / pixel measures (via functional group macros), so a SEG is not necessarily on the CT grid — it can be a sparse set of labelled planes (see lesson 5). - Segment identity:
SegmentSequencedefines segment numbers, labels, and properties (e.g. “Tumour”, “Liver”). - Segmentation type
(0062,0001)enumerates three encodings (PS3.3 C.8.20.2):BINARY— 1 bit per voxel, in/out of the segment;FRACTIONAL— 8-bit, a probability/occupancy per voxel (withSegmentation Fractional TypeandMaximum Fractional Value);LABELMAP— integer label per voxel (8 or 16-bit), encoding multiple non-overlapping segments in one object. This is the closest DICOM analogue of a multi-label mask array.
- Encoding: binary pixels are packed 8 one-bit pixels per byte (PS3.5
bit-packing); fractional/labelmap are more array-like but still need a decoder.
Use highdicom, dcmqi, or TRACE-CT’s
decode_seg_file().
RTSTRUCT (RT Structure Set Storage)
The radiotherapy legacy format. Structures are stored as coplanar contours (lists of 3D points per slice), not as voxels. Converting RTSTRUCT → mask requires a rasterisation step that fills the contours on the reference grid. Watch out for: contours that do not close cleanly, slice gaps, and the implicit reference image grid (you must supply it). RTSTRUCT↔mask conversion is lossy and tool-dependent — know it exists, and treat its output as approximate.
Where information is silently lost
Round-tripping between representations destroys information in specific ways. This is the reference table to keep:
Where SEG↔mask silently loses information:
- binary quantisation of a fractional boundary (a 0.7-occupancy voxel becomes 1);
- nearest-neighbour snapping when the SEG frame grid is finer or coarser than the CT;
- dropped frames for segments outside the reference image extent;
- loss of the source-image references if you export only a
.nrrdmask.
The two skills that matter for the CT/radiomics path are the two conversions you will actually perform:
- Decode a SEG onto a reference grid, validating that the SEG’s per-frame geometry matches the CT (or resampling it where it does not).
- Round-trip a mask (mask → SEG → mask) and know where it lost fidelity: fractional edges collapse to binary; off-grid frames snap to the nearest reference voxel.
Stop and think — then reveal
You export a segmentation as a .nrrd mask array and delete the DICOM SEG. What
three pieces of information did you almost certainly lose?
- The source-image references — the SEG’s
ReferencedSeriesSequence/ sourceSOPInstanceUIDs that tied the mask to specific CT slices. The.nrrdalone no longer says which CT it belongs to. - Segment identity / labels — if there were multiple named segments, a bare mask may collapse them to integers with no names or properties.
- Fractional boundary detail — if the SEG was
FRACTIONAL, exporting a binary mask quantises the boundary probabilities to 0/1.
For computation a mask is fine; for exchange and provenance, keep the SEG (or at least record the source UIDs alongside the mask).
What to retain
- Three representations — binary mask, DICOM SEG, RTSTRUCT — describe the same structure but preserve different geometry, references, and fidelity.
- A binary mask must share the reference image’s geometry; “same shape” is not enough.
- A DICOM SEG carries source-image references and per-frame geometry; it is not necessarily on the CT grid.
- Conversions are lossy in known places: fractional→binary quantises edges, off-grid frames snap, and exporting only a mask drops the source references.
Next: the most consequential conversion of all — why image and mask resampling must differ, and why that choice changes every boundary feature.