pydicom / pydicom

Read, modify and write DICOM files with python code

Home Page:https://pydicom.github.io/pydicom/dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decoding failure for JPEG-LS when Bits Allocated is 16 and Bit Stored <= 8

scaramallion opened this issue · comments

When pixel data is JPEG-LS encoded with a bits stored <= 8 (i.e. JPEG-LS samples per pixel/precision) then decoding fails if the Bits Allocated value is 16. GDCM will return data but it looks like there's a memory overflow (?) issue going on, while pylibjpeg and pyjpegls will raise an exception because the returned data length doesn't match the expected length.

image
Left: GDCM, right: reference

I don't think it's possible to have a 16-bit input -> precision <=8 -> 16-bit output when using JPEG-LS, and I doubt it's possible for JPEG extended and J2K. That would imply the correct thing to do in this case is to return an 8-bit array when the precision actually is <= 8.

The other side of the coin is if the bits stored is wrong but bits allocated is correct... ugh! With pyjpegls and pylibjpeg we can check the length of the returned image data to determine the appropriate bits stored value, but GDCM will return invalid data of the correct length no matter what. In which case the only other alternative is to parse the JLS stream for the sample precision.