fix(dicomImageLoader): reset planarConfiguration to 0 after JPEG Lossless decode#2778
Conversation
…less decode jpeg-lossless-decoder-js always outputs pixel-interleaved data (RGBRGB...) regardless of the DICOM Planar Configuration tag (0028,0006). When that tag is 1 (band-interleaved), downstream convertColorSpace incorrectly calls convertRGBColorByPlane on interleaved data, producing severe rainbow color artifacts on RGB images encoded with transfer syntaxes 1.2.840.10008.1.2.4.57 and 1.2.840.10008.1.2.4.70. The same issue almost certainly exists in decodeJPEGLS, decodeJPEG2000, and decodeHTJ2K, which likewise do not reset planarConfiguration after decoding. This was confirmed for decodeJPEG2000: manually setting planarConfiguration=1 on a JPEG 2000 RGB image reproduced the same rainbow artifacts. Those decoders are not changed here as test images directly from the modality were not obtained to verify the fix end-to-end.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIn ChangesJPEG-lossless decoder planarConfiguration fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Context
jpeg-lossless-decoder-jsalways outputs pixel-interleaved data (RGBRGBRGB…) regardless of the DICOM Planar Configuration tag (0028,0006). This is hardcoded in itssetValueRGBimplementation:outputData[3 * pixelIndex + componentIndex] = valueHowever, when a DICOM file has Planar Configuration = 1 (band-interleaved:
RRRR…GGGG…BBBB), that value is read intoimageFrame.planarConfigurationbefore decoding and was never corrected afterwards.Downstream,
convertColorSpacereadsimageFrame.planarConfigurationand calls eitherconvertRGBColorByPixel(PC=0) orconvertRGBColorByPlane(PC=1). When PC is left as 1,convertRGBColorByPlaneis called on interleaved data,producing severe rainbow colour artifacts.
Per DICOM PS 3.5 §8.2.1, Planar Configuration is not meaningful for compressed transfer syntaxes and shall be ignored. The decoder output format governs.
Affected transfer syntaxes:
1.2.840.10008.1.2.4.57-> JPEG Lossless (Process 14)1.2.840.10008.1.2.4.70-> JPEG Lossless SV1 (Process 14 SV1)Example Artifacts:
Changes & Results
Change: One line added to
packages/dicomImageLoader/src/shared/decoders/decodeJPEGLossless.ts. We forceimageFrame.planarConfiguration = 0after the decoder runs and beforepixelDatais assigned, so the downstream color space converter always takes the correct pixel-interleaved path.Before: RGB images stored with JPEG Lossless transfer syntax and Planar Configuration = 1 rendered with severe rainbow color artifacts.
After: Those images render correctly regardless of the Planar Configuration value in the DICOM header.
Related: The same issue almost certainly exists in
decodeJPEGLS,decodeJPEG2000, anddecodeHTJ2K, which likewise do not resetplanarConfigurationafter decoding. This was confirmed fordecodeJPEG2000: manually settingplanarConfiguration=1on a JPEG 2000 RGB image reproduced the same rainbow artifacts. Those decoders are left for a follow-up as test images directly from the modality were not obtained. If this fix is acceptable for JPEG Lossless decoding, I'd gladly add it to the other decoders.Testing
Two anonymized 1.2.840.10008.1.2.4.70 DICOM files are attached below, one with Planar Configuration = 1 (reproduces the rainbow artifact on the unfixed build) and one with Planar Configuration = 0 (correct reference rendering).
mainbranch to confirm the artifact is present and this fix resolves it.Example Redacted Files.zip
Checklist
PR
semantic-release format and guidelines.
Code
etc.)
Public Documentation Updates
additions or removals.
Tested Environment
Summary by CodeRabbit