Skip to content

Use DCMTK for all CIELab/RGB color conversions. - #565

Open
michaelonken wants to merge 1 commit into
masterfrom
color_conversion
Open

michaelonken wants to merge 1 commit into
masterfrom
color_conversion

Conversation

@michaelonken

@michaelonken michaelonken commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

This changes the colors, not only the precision. DICOM stores the Recommended Display CIELab Value in the same way as the ICC Profile Connection Space, so the values are relative to the D50 illuminant. Both old implementations (dcmqi's ColorUtilities and DCMTK up to commit 88105877c from September 2026) computed CIELab relative to D65 instead. DCMTK now converts sRGB -> XYZ (D65)-> Bradford adaptation to D50 -> CIELab. It uses the matrices from the CSS Color Module Level 4 sample code (taken over from PixelMed code).

Effect on existing files: SEG objects written by older versions contain D65-based CIELab values. When this version reads them, the RGB values in the JSON metadata differ a little for colored segments. The largest change is for pure blue. Gray values do not change. Files written by this version are read back exactly (the 8-bit round trip is exact for all 16.7 million RGB values).

Other fixes included: results outside the sRGB range are now clamped (before, they wrapped around in unsigned), results are rounded instead of truncated, and the integer division bug in the old inverse f function (black was read back as 36,36,36) is gone together with the old code.

This PR updates DCMTK to 4e89d4f (including mentioned 88105877c), whose IODCIELabUtil now computes CIELab relative to the ICC PCS white point (D50) like PixelMed (see #563), and drop dcmqi's own ColorUtilities, which used D65.

  • Convert Recommended Display RGB/CIELab values via IODCIELabUtil
  • Derive the fallback CIELab value from the default RGB 128,174,128
  • Encode background black as 0/32896/32896 (a*=b*=0), not 32768
  • Round palette LUT entries instead of truncating them
  • Remove the Java reference implementation of the old conversion.

Update DCMTK to 4e89d4f, whose IODCIELabUtil now computes CIELab
relative to the ICC PCS white point (D50) like PixelMed (see #563),
and drop dcmqi's own ColorUtilities, which used D65.

- Convert Recommended Display RGB/CIELab values via IODCIELabUtil
- Derive the fallback CIELab value from the default RGB 128,174,128
- Encode background black as 0/32896/32896 (a*=b*=0), not 32768
- Round palette LUT entries instead of truncating them
- Remove the Java reference implementation of the old conversion.
@sonarqubecloud

Copy link
Copy Markdown

@fedorov

fedorov commented Sep 25, 2026

Copy link
Copy Markdown
Member

@mhalle - fyi in case you want to check!

@fedorov

fedorov commented Oct 7, 2026

Copy link
Copy Markdown
Member

Related highdicom fix: ImagingDataCommons/highdicom#469

@fedorov

fedorov commented Oct 7, 2026

Copy link
Copy Markdown
Member

Related dcmjs fix: dcmjs-org/dcmjs#598

This branch has not been deployed

No deployments
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.

2 participants