Skip to content

Ft itk2label#536

Open
michaelonken wants to merge 5 commits intomasterfrom
Ft_itk2label
Open

Ft itk2label#536
michaelonken wants to merge 5 commits intomasterfrom
Ft_itk2label

Conversation

@michaelonken
Copy link
Copy Markdown
Member

Add direct ITK to DICOM Labelmap conversion.

Also includes PRs #534 and #535 (the latter being probably optional).

Extend itkimage2segimage with a --segmentationType option (default
"binary", preserving prior behavior) that, when set to "labelmap",
emits a DICOM Labelmap Segmentation (Sup 243) directly from an ITK
image. Previously the only way to produce a labelmap was to convert
to a binary Segmentation first and then run bin2labelsegimage;
this removes the intermediate step.

In labelmap mode foreground segments are numbered 1..N (or taken
from labelIDs when --useLabelIDAsSegmentNumber is set); pixel value
0 is reserved for the implicit background. If any frame contains
pixel 0 a Background segment (Property Type DCM 125040) is added
automatically so every pixel value is covered by a Segment Sequence
item, as required by Sup 243. Bit depth is 8-bit when the segment
count fits, else 16-bit. Overlapping foreground segments are
rejected because each labelmap pixel can carry only one segment
number.

The frame-scan + background-segment-creation logic that this new
path needs is identical to what Bin2Label already does for
binary->labelmap conversion. It is consolidated into a shared
ConverterBase::addBackgroundSegmentIfNeeded() helper, and
DcmBinToLabelConverter's member function becomes a thin wrapper
that delegates and adds the PALETTE-mode LUT prepend on top.

Also adds a 2-segment metadata example
(doc/examples/seg-example_liver_spine.json) used by new CTest
entries:

  • itkimage2segimage_makeSEG_labelmap: single-segment conversion.
  • itkimage2segimage_makeSEG_labelmap_multi: multi-segment
    conversion. Regression guard for segment numbering, which is
    not exercised by single-segment inputs.
  • itkimage2segimage_makeSEG_labelmap_multi_labelID: same with
    --useLabelIDAsSegmentNumber.
  • itkimage2segimage_makeSEG_labelmap_overlap: liver/heart pair
    overlaps on 522 pixels; conversion must fail (WILL_FAIL).
  • segimage2itkimage_makeNRRD_from_labelmap_{direct,multi}:
    pixel-perfect round-trip back to NRRD against existing baselines.

dciodvfy is intentionally not run on the new labelmap outputs;
all labelmap segmentations emitted by dcmqi today (both Bin2Label
and this new path) fail dciodvfy because Type 2C PatientOrientation
is not populated under GeneralImage. This is a pre-existing
gap and is documented inline in the CMakeLists.

When converting DICOM binary segmentations to DICOM labelmaps,
some pixels are likely not covered from any of the the segments.
Since the pixels are initially set to 0, all non-covered pixels
will be "background" and must be marked as such.

This is done by scanning all pixels after conversion and if a 0 is
found, a segment using codes for denoting "background" will be inserted
automatically.

The alternative would be to set Pixel Padding Value. This could be
introduced as an option later, but for now the background segment
seems to be better supported by consuming applications.
Also for the newly added background segment, don't write
(0062,000D) Recommended Display CIELab Value either.

Also some minor changes.
Performance optimizations for segmentation/parametric maps (dcmiod,
dcmfg, dcmseg).

It also includes a simpler mechanism to add external modules to the
DCMTK CMake build (e.g. the JPEG2000 codec from DCMTKcs, see
https://github.com/lassoan/DCMTKcs).
Extend itkimage2segimage with a --segmentationType option (default
"binary", preserving prior behavior) that, when set to "labelmap",
emits a DICOM Labelmap Segmentation (Sup 243) directly from an ITK
image. Previously the only way to produce a labelmap was to convert
to a binary Segmentation first and then run bin2labelsegimage;
this removes the intermediate step.

In labelmap mode foreground segments are numbered 1..N (or taken
from labelIDs when --useLabelIDAsSegmentNumber is set); pixel value
0 is reserved for the implicit background. If any frame contains
pixel 0 a Background segment (Property Type DCM 125040) is added
automatically so every pixel value is covered by a Segment Sequence
item, as required by Sup 243. Bit depth is 8-bit when the segment
count fits, else 16-bit. Overlapping foreground segments are
rejected because each labelmap pixel can carry only one segment
number.

The frame-scan + background-segment-creation logic that this new
path needs is identical to what Bin2Label already does for
binary->labelmap conversion. It is consolidated into a shared
ConverterBase::addBackgroundSegmentIfNeeded() helper, and
DcmBinToLabelConverter's member function becomes a thin wrapper
that delegates and adds the PALETTE-mode LUT prepend on top.

Also adds a 2-segment metadata example
(doc/examples/seg-example_liver_spine.json) used by new CTest
entries:
- itkimage2segimage_makeSEG_labelmap: single-segment conversion.
- itkimage2segimage_makeSEG_labelmap_multi: multi-segment
  conversion. Regression guard for segment numbering, which is
  not exercised by single-segment inputs.
- itkimage2segimage_makeSEG_labelmap_multi_labelID: same with
  --useLabelIDAsSegmentNumber.
- itkimage2segimage_makeSEG_labelmap_overlap: liver/heart pair
  overlaps on 522 pixels; conversion must fail (WILL_FAIL).
- segimage2itkimage_makeNRRD_from_labelmap_{direct,multi}:
  pixel-perfect round-trip back to NRRD against existing baselines.

dciodvfy is intentionally not run on the new labelmap outputs;
all labelmap segmentations emitted by dcmqi today (both Bin2Label
and this new path) fail dciodvfy because Type 2C PatientOrientation
is not populated under GeneralImage. This is a pre-existing
gap and is documented inline in the CMakeLists.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 8, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant