I've found a couple of issues with decompressing JPEG-LS pixel data:
Decoding single sample pixel data with a JPEG-LS precision of 6 or 7 fails, but all other precisions in (2, 16) work.
./gdcmconv -i JLSL_08_07_0_1F.dcm -o out.dcm -w -V
Error: In .../GDCM/Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx, line 220, function bool gdcm::JPEGLSCodec::DecodeByStreamsCommon(const char*, size_t, std::vector<unsigned char>&)
Could not decode JPEG-LS stream
Error: In .../GDCM/Source/MediaStorageAndFileFormat/gdcmImageChangeTransferSyntax.cxx, line 423, function bool gdcm::ImageChangeTransferSyntax::Change()
Error in getting buffer from input image.
Could not change the Transfer Syntax: ../JLSL_08_07_0_1F.dcm
If the dataset's Bits Allocated is 16, but the JPEG-LS precision (and Bits Stored) is <= 8 then the decompression fails due to a length check:
./gdcmconv -i JLSL_16_08_0_1F.dcm -o out.dcm -w -V
gdcmconv: /home/dean/Coding/src/GDCM/Source/MediaStorageAndFileFormat/gdcmBitmap.cxx:726: bool gdcm::Bitmap::TryJPEGLSCodec(char*, bool&) const: Assertion `len <= outbv->GetLength()' failed.
Aborted
JPEG-LS doesn't track signedness, so when Pixel Representation 1 and Bits Stored/precision is less than Bits Allocated the sign bit is lost on decompression and unsigned values are returned. Incorrect output is seen with gdcmconv -i JLSL_16_15_1_1F.dcm -o out.dcm -w
Attached are minimal test datasets with a JPEG-LS precision of 5, 6, 7 and 8-bits (the four JLSL_08_0X_0_1F.dcm files), a JPEG-LS precision/Bits Stored of 8 and a Bits Allocated of 16 (JLSL_16_08_0_1F.dcm) and a pair of signed Bits Allocated 16, with Bits Stored/precision 15 and 16 (JLSL_16_15_1_1F.dcm and JLSL_16_16_1_1F.dcm).
Thanks!
Forgot to mention, this is all with the current
masteron github (3.1.0?). I've also seen the same behaviour in v3.0.23.will work if GDCM is compiled with the newer CharLS (GDCM_USE_SYSTEM_CHARLS), as well as the other JLSL_08_ files.
JLSL_16_08_0_1F.dcm seems to have wrong DICOM BitsAllocated, why it is 16, JPEGLS says bitsPerSample = 8. so the issue, not sure.
I didn't look at 'sign' issue, BTW.
@scaramallion could you confirm what I see on my side:
In other word, per DCMTK 3.6.9 only two files do not trigger a fatal error: JLSL_16_15_1_1F.dcm & JLSL_16_16_1_1F.dcm.
Now if I compare GDCM vs DCMTK on JLSL_16_16_1_1F.dcm here is what I get:
lead to:
Could you rephrase your bug report and help me understand what you output you are expecting on JLSL_16_16_1_1F.dcm ? Thanks
Sorry I realized that
JLSL_08_08_0_1F.dcmought to work (per DCMTK). Here is what I see using gdcm from Debian/stable: