Skip to content

rordenlab/itu-t81_issue

Repository files navigation

JPEG Conversion and Decoder Discrepancy

This repository demonstrates a decoding discrepancy affecting certain lossless JPEG images extracted from DICOM files.

The included file dcm.jpg is a single-slice example extracted from the problematic DICOM dataset described in rordenlab/dcm2niix#977.
In that dataset, slices that contain no intensity variability (completely empty slices) are misdecoded — each pixel should have an intensity of 24, yet dcm2niix and several independent JPEG lossless decoders both report a value of 28675.

This image is encoded in the legacy ITU-T81 lossless JPEG format (specification PDF).

Interestingly, independent JavaScript implementations by Mango replicate the same behavior observed in dcm2niix’s C decoder.
Both Daikon 1.1’s lossless.js and the newer JPEGLosslessDecoderJS produce identical incorrect results.

1. Using Daikon’s lossless.js

node decode.js dcm.jpg
First three voxel values: 28675, 28675, 28675

2. Using jpeg-lossless-decoder-js

npm install jpeg-lossless-decoder-js
node decode_jpeglossless.js dcm.jpg
Found at require(...).Decoder
Decoded bytes: 524288
First 3 raw bytes: 3, 112, 3
First 3 samples as Int16 LE: 28675, 28675, 28675

Both decoders interpret the first pixel as 28675 rather than 24.

3. Verification with ImageMagick

ImageMagick correctly reports a pixel intensity of 24 for the same file (assuming proper point transform handling):

magick dcm.jpg -depth 16 -format "%[fx:u.p{0,0}*65535]\n" info:
24

(Note: ImageMagick may internally use a similar JPEG decoder to the one that created the original compression, so its correctness could depend on that implementation. However, the decoded result here matches the expected 16-bit pixel value of 24.)

4. Summary

Tool / Library Reported Value Expected
dcm2niix (C) 28675 24
Daikon lossless.js 28675 24
JPEGLosslessDecoderJS 28675 24
ImageMagick 24 Correct

The error likely arises from signed/unsigned interpretation and missing point transform handling in these JPEG lossless decoders.

6. Illustrating the Issues in DICOMs

You can experience the issue with the source images by using the mangoviewer and opening the sample DICOM dataset. Note that all the empty slices superior to the brai age extremely bright instead of dark.

Mango

5. References

About

Different interpretations for ITU-T81 compression

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published