DICOM segmentation and radiotherapy
DICOM segmentation and radiotherapy support places derived clinical data over its source images. DICOM SEG becomes editable labelmap data, while RT Structure Set data becomes contour data. Both forms stay linked to the primary imaging and use the shared segmentation state so that they can be viewed, managed, and saved as derived studies.
Derived data model
Derived data describes an image or structure that belongs with a source image series. The viewer uses DICOM references to find that source, select a matching representation, and keep the derived data aligned with the source view.
Source-image association
SEG and RT Structure Set display sets are overlay display sets. Each one points to a referenced display set and uses its image identifiers and frame of reference to place the derived data on the correct source images.
If the source display set is not ready when the derived series arrives, the handler waits for matching display sets to be added. If no source is available, a customization hook can explain or handle the missing reference. When no such handler exists, the SEG or RT viewport skips derived rendering instead of trying to create a viewport without a valid image base.
References: extensions/…/getSopClassHandlerModule.ts• L242-358 extensions/…/OHIFCornerstoneSEGViewport.tsx• L54-85 extensions/…/getSopClassHandlerModule.ts• L21-143 extensions/…/OHIFCornerstoneRTViewport.tsx• L50-80
Representation types
The segmentation service maps each DICOM form to the representation that matches its data model. A labelmap stores segment labels in image data. A contour representation stores shapes in patient space.
| DICOM data | Viewer representation | Main use |
|---|---|---|
| DICOM SEG | Labelmap | Show or edit segmented pixels over source images |
| RT Structure Set | Contour | Show radiotherapy regions and navigate to their source slices |
The same segmentation state can also support surface views in 3D. That view choice does not change the DICOM source or its link to the primary images.
References: extensions/…/getSopClassHandlerModule.ts• L607-621 extensions/…/getSopClassHandlerModule.ts• L240-253
Derived-data lifecycle
Loading prepares the DICOM content and its segment or contour metadata. Hydration attaches the prepared data to a source viewport for display and interaction. The shared load promise prevents repeated requests when more than one viewer action needs the same derived data.
The normal lifecycle has four stages:
- A SOP class handler turns the DICOM series into a derived display set.
- The display set loads pixel or contour data and creates shared segmentation state.
- The viewport attaches the labelmap or contour representation to the referenced source view.
- The user changes visibility, selection, style, or geometry through the segmentation controls and tools.
This diagram shows how a derived DICOM series reaches the rendered source image.
flowchart LR
A[DICOM SEG or RT Structure Set] --> B[Derived display set]
B --> C[Referenced source image]
B --> D[Segmentation state]
C --> E[Source viewport]
D --> F[Labelmap or contour representation]
E --> G[Rendered source image]
F --> G
G --> H[Segmentation controls and tools]
References: extensions/…/getSopClassHandlerModule.ts• L377-430 extensions/…/getSopClassHandlerModule.ts• L157-199
DICOM SEG
DICOM SEG carries segmented pixels that correspond to a source image series. The SEG extension loads those pixels with their segment metadata, adds them to shared segmentation state, and lets the viewer display or edit them as a labelmap.
SEG loading
The SEG handler accepts supported DICOM SEG storage classes and creates a derived display set for the series. It resolves the referenced source series before it loads SEG frames. The loader supports local and active data sources, expands multi-frame data into frame image IDs, and can fetch the instance as one object before decoding its frames.
The loader decodes frames with bounded concurrency and reports progress to the segmentation service. This supports large multi-frame SEG objects without requiring the viewer to make one independent request for every frame. The loaded result includes source-image links, labelmap images, segment labels, colors, algorithm details, and basic segment metadata. DICOM display color is used when present. A default color is used when it is absent. The extension is a read workflow for the host imaging and viewer services. Its package declares the shared host peers and the Cornerstone and VTK runtime support needed by the SEG workflow. Its production bundle is built from .rspack/rspack.prod.js.
References: extensions/…/getSopClassHandlerModule.ts• L16-26 extensions/…/getSopClassHandlerModule.ts• L242-358 extensions/…/getSopClassHandlerModule.ts• L377-601 extensions/…/package.json• L1-57 extensions/…/rspack.prod.js• L1-57
SEG hydration
The SEG viewport is a source-image viewport with the SEG display set added as a second layer. This is important because SEG pixels do not provide a useful grayscale base view by themselves. The viewport renders the referenced image first and places the labelmap over it.
Hydration can ask the user for permission because it loads and processes derived data. After approval, the viewer adds the segmentation representation to the active source viewport and keeps its position and appearance so the overlay can return after a layout change. The first slice that contains segment data becomes the initial navigation target when one is available. If the source reference is missing, the viewport does not render the SEG layer unless a customization handler manages that case.
References: extensions/…/OHIFCornerstoneSEGViewport.tsx• L87-105 extensions/…/OHIFCornerstoneSEGViewport.tsx• L109-161 extensions/…/promptHydrateSEG.ts• L3-23
SEG editing and storage
SEG data uses shared segmentation state for active segments, labels, colors, visibility, locks, and cached statistics. The segmentation mode adds drawing and edit tools to the normal image tools. A user can therefore work on the derived labelmap without replacing the primary image.
Contour segmentation controls also let a user merge, intersect, or subtract two selected segments. The result can replace a selected segment or become a new named segment. This supports derived contour edits while keeping segment identity in the shared segmentation state.
The save flow can generate a new DICOM SEG from the current labelmap and send or download it through a selected data source. It keeps the source-series choice and series metadata with the derived result. A data source can define its own SEG storage settings because different back ends can support different encodings.
The export path preserves the link between voxel labels and segment identity for each labelmap layer. Labels that have no matching segment are excluded from the DICOM result instead of becoming new segments. Overlapping segments need special handling because a single-label-per-voxel encoding cannot keep two labels on the same source slice. The export path therefore uses an overlap-safe encoding when the current segmentation has multiple layers, and it requires the referenced source images to be loaded before it creates the DICOM object.
References: extensions/…/LogicalContourOperationsOptions.tsx• L25-48 extensions/…/LogicalContourOperationsOptions.tsx• L94-163 extensions/…/commandsModule.ts• L101-339 extensions/…/commandsModule.ts• L374-500 extensions/…/labelmapLayerSegmentIndices.ts• L1-61 extensions/…/package.json• L43-57
Radiotherapy structures
The radiotherapy extension handles DICOM RT Structure Set data. An RT Structure Set describes named regions of interest as contours in patient space. The viewer loads those regions and presents them as a contour segmentation over the referenced imaging series.
RT Structure Set loading
The RT handler creates an overlay display set for an RT Structure Set and resolves the source series from its DICOM references. If the direct referenced-series sequence is absent, it can derive the series links from frame-of-reference references. The shared load promise lets repeated requests use the same load operation.
The loaded structure set keeps ROI names, numbers, descriptions, colors, observation data, contour points, and referenced source SOP instances. Unsupported contour geometry remains in the loaded data but is marked as unsupported for rendering. The extension is a separate read workflow for the host imaging and viewer services. Its package declares the same host peer boundary as the SEG workflow. Its production bundle is built from .rspack/rspack.prod.js.
References: extensions/…/getSopClassHandlerModule.ts• L10-18 extensions/…/getSopClassHandlerModule.ts• L21-143 extensions/…/getSopClassHandlerModule.ts• L157-199 extensions/…/package.json• L1-52 extensions/…/rspack.prod.js• L1-51
RT contour representation
The segmentation service maps each ROI to contour geometry and registers it as a contour representation. The ROI number provides the stable segment index. The ROI name identifies the segment for the panel. The DICOM color supplies its display color.
The contour geometry stays separate from the source image pixels. This lets the viewer show structure boundaries in a stack, MPR, or other compatible source view without changing the source image data.
References: extensions/…/mapROIContoursToRTStructData.ts• L10-35 extensions/…/getSopClassHandlerModule.ts• L161-188
RT hydration and navigation
The RT viewport follows the same source-plus-overlay model as the SEG viewport. It gives the source display set to the Cornerstone viewport and keeps RT contours as the second layer. The first source image referenced by a contour becomes the navigation target when the link can be resolved. If the source reference is missing, the viewport uses the same guarded path as SEG and skips rendering when no customization handler can manage the missing source.
After the user accepts hydration, the viewer returns to the referenced source viewport. It saves the contour representation and source position before that change. This lets the user inspect and manage regions while keeping the normal image layout.
References: extensions/…/OHIFCornerstoneRTViewport.tsx• L50-80 extensions/…/OHIFCornerstoneRTViewport.tsx• L81-130 extensions/…/OHIFCornerstoneRTViewport.tsx• L178-201 extensions/…/promptHydrateRT.ts• L3-23
RT Structure Set export
The shared segmentation commands can turn the current contour representation into a DICOM RT Structure Set. The user can download it or store it through a selected data source. The generated object keeps contour colors and the chosen source-series details. Its structure-set creation time is set as part of the export.
This export path gives contour edits the same manage-and-save workflow as SEG data. It creates a derived RT Structure Set that refers back to the source images rather than replacing them.
References: extensions/…/commandsModule.ts• L374-500 extensions/…/commandsModule.ts• L503-515
Shared viewport management
SEG and RT overlays use shared viewport and segmentation rules. The source layer remains stable while derived representations can be added, removed, or restored for a viewport.
Overlay rendering
When a viewport contains an overlay display set, the viewport service finds its referenced source image IDs and schedules the overlay representation after the source view is prepared. SEG uses a labelmap representation. RT Structure Set uses a contour representation.
The service waits for segmentation state before it attaches the representation. A bounded wait prevents a failed load from blocking viewport readiness forever. Multiple overlays can be managed as separate representations while the source display set remains the base layer.
References: extensions/…/CornerstoneViewportService.ts• L1300-1464 extensions/…/layerConfigurationUtils.ts• L3 extensions/…/layerConfigurationUtils.ts• L64-95
Segmentation state
The segmentation service is the shared state owner for loaded segmentations and their viewport representations. It tracks the active segmentation, active segment, and segment appearance for each viewport. Events notify panels and viewports when data, representations, or styles change.
This shared state lets an overlay survive viewport remounts. It also lets several viewports show the same segmentation with coordinated segment settings. Cleanup removes representations when an overlay viewport or viewing mode ends.
References: extensions/…/SegmentationService.ts• L82-104 extensions/…/SegmentationService.ts• L878-962 extensions/…/SegmentationService.ts• L991-1059 extensions/…/SegmentationService.ts• L1466-1545
Segmentation mode
The segmentation mode provides a focused layout for source images and derived data. It includes labelmap and contour panels, dedicated SEG and RT viewports, and tools to inspect or edit segmentations.
The mode also watches segmentation events. When the first representation becomes active, it can move the user to the matching segmentation panel. This keeps the panel type aligned with the active labelmap or contour data.
References: modes/…/index.tsx• L17-117 modes/…/setUpAutoTabSwitchHandler.ts• L1-35
Related pages
Read Cornerstone imaging integration for the extension boundary and shared service contracts. Read Cornerstone viewport and tools for viewport lifecycle, tool groups, and presentation state. Read structured reports and measurements for report-linked findings and measurement workflows. Read segmentation and microscopy modes for the user-facing segmentation mode and its relationship to other imaging modes.
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to SEG or RT reference matching must keep the derived display set linked to the correct source series and frame of reference.
- Changes to SEG or RT load completion must preserve the order in which segmentation state is created and the completion event is sent.
- Changes to SEG frame loading must keep source-slice alignment, frame metadata, progress reporting, frame-fetch fallback, and the shared in-flight load promise consistent.
- Changes to overlay mounting must keep the source display set as the base layer and attach the correct labelmap or contour type.
- Changes to hydration must keep saved source position and segmentation presentation aligned when the overlay returns to the source viewport.
- Changes to logical contour operations must keep the selected segment indices, result segment identity, and active segmentation consistent with the command that applies the operation.
- Changes to SEG labelmap export must keep layer label values mapped to the right segment indices and exclude labels that have no segment.
- Changes to SEG overlap handling must keep import, viewport rendering, and DICOM export consistent about layer identity and encoding.
- Changes to SEG or RT export must keep the selected predecessor series, series metadata, colors, creation time, writer identity, and destination data source aligned with the generated DICOM object.
- Changes to data-source SEG settings must keep the selected store's encoding rules separate from the global defaults.
- Changes to RT source matching must keep direct series references and frame-of-reference-derived references equivalent.
- Changes to RT contour mapping must preserve ROI number, ROI name, color, geometry ID, and referenced source SOP identity.
- Changes to segmentation events must preserve panel updates, active-segment state, and representation cleanup.
- Changes to either extension's package contract or Rspack production config must preserve its Cornerstone and OHIF peer integration, supported bundle entry point, external package boundary, and runtime package needs.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A SEG or RT display set has no matching source display set | The derived viewport has no valid image base and cannot place the overlay | Resolve the reference before hydration and use the missing-reference customization path when needed; skip rendering if no handler exists |
| SEG frame IDs do not match the referenced source image order | Labelmap data appears on the wrong slices or cannot be linked to the source | Build frame IDs from the SEG instance and preserve source image order during parsing |
| A SEG representation is attached before segmentation state exists | The source image renders without its labelmap | Create segmentation state before signaling load completion and wait for it during overlay setup |
| A labelmap layer contains a label value with no matching segment | Those voxels are absent from the exported DICOM SEG | Preserve the layer-to-segment mapping and map unbound values to no segment during export |
| An RT Structure Set has no usable contour data | The RT display set loads but has no regions to show | Validate the structure set and contour sequences before creating the contour representation |
| A logical contour operation uses an invalid or missing segment choice | The requested derived contour cannot be applied to the active segmentation | Require two segment choices and keep the result segment in the active segmentation |
| Overlapping SEG layers use a single-label encoding | Some labels are lost in the rendered or stored result | Keep overlapping layers separate and use an encoding that supports multiple labels per source slice |
| SEG export references a source image that is not loaded | DICOM generation stops instead of producing a dataset with invalid source frames | Fully load the referenced source series before storing or downloading the SEG |
| A selected data source has incompatible SEG store settings | The generated object uses an encoding that the target back end cannot accept | Resolve store settings from the data source used for the save |
| A derived overlay is hydrated without restoring its saved presentation | The user returns to the wrong slice or loses overlay appearance | Store source position and segmentation presentation before replacing the overlay viewport |
| A SEG or RT load never completes | Viewport setup can remain blocked or the overlay can stay absent | Resolve load failures and keep a bounded wait for representation setup |
| An extension package or production bundle loses a required peer, runtime dependency, external boundary, or entry point | The SEG or RT workflow may not load in the host viewer or may not produce its distributable bundle | Keep package metadata and .rspack/rspack.prod.js aligned with the workspace dependencies, external packages, runtime packages, and output name |
Key files
| File | Why to read it |
|---|---|
| extensions/…/SegmentationService.ts | Shared segmentation state, representations, segment state, and events |
| extensions/…/CornerstoneViewportService.ts | Source-plus-overlay viewport setup and representation attachment |
| extensions/…/getSopClassHandlerModule.ts | SEG reference resolution, frame loading, pixel parsing, segment metadata, progress, and load lifecycle |
| extensions/…/OHIFCornerstoneSEGViewport.tsx | SEG source viewport composition, guarded source lookup, and hydration behavior |
| extensions/…/LogicalContourOperationsOptions.tsx | User controls for combining contour segments and creating a result segment |
| extensions/…/commandsModule.ts | SEG generation, overlap-aware export, data-source storage, and RT Structure Set generation and download |
| extensions/…/labelmapLayerSegmentIndices.ts | Label-to-segment mapping that keeps layered and overlapping SEG export aligned |
| extensions/…/package.json | SEG read-workflow boundary, host peer contracts, runtime dependencies, and package build outputs |
| extensions/…/rspack.prod.js | SEG production bundle entry, external package boundary, and output wiring |
| extensions/…/getSopClassHandlerModule.ts | RT Structure Set display-set creation, source reference handling, and frame-of-reference fallback |
| extensions/…/loadRTStruct.js | RT contour loading and structure metadata preparation |
| extensions/…/OHIFCornerstoneRTViewport.tsx | RT source viewport composition, guarded source lookup, and hydration behavior |
| extensions/…/package.json | RT read-workflow boundary, host peer contracts, runtime package boundary, and package build outputs |
| extensions/…/rspack.prod.js | RT production bundle entry, external package boundary, and output wiring |
| extensions/…/mapROIContoursToRTStructData.ts | Mapping from RT ROI contours to shared contour segmentation data |
| modes/…/index.tsx | Focused segmentation layout, panels, viewports, and mode wiring |
| modes/…/initToolGroups.ts | User interaction groups for labelmap and contour work |