GDCM-based decompression failure #1885
Replies: 2 comments 3 replies
-
Is it too much trouble for you to attach an example of a faulty JPEG? I'd like to have a closer look |
Beta Was this translation helpful? Give feedback.
-
Still working on getting permission to share the pixel data. But in the meantime, I have found some more interesting things. If I try to decompress the whole image with either for frame in {1..<NumberOfFrames>}; do
dcmj2pnm --write-jpeg --frame $frame $IMAGE > "${frame}.jpeg"
done I get 28 images I can open in a normal image viewer. Additionally I've spent some time stepping through from pydicom import dcmread
from pydicom.encaps import decode_data_sequence
dcm = dcmread(PATH)
data_seq = decode_data_sequence(dcm.PixelData)
for i in range(0, len(data_seq), 7):
raw = b''.join(data_seq[i:i+7])
with open(f'/tmp/dicom/{i}.jpeg', 'wb') as fp:
fp.write(raw) $ /tmp/dicom/file 0.jpeg
0.jpeg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, comment: "Intel(R) JPEG Library, version [2.0.16.48]", baseline, precision 8, 800x600, components 3 Like I said, I'll continue trying to post the actual data, but maybe some of this will ring a bell |
Beta Was this translation helpful? Give feedback.
-
I just wanted to post this in case anyone else runs into it, I don't think its an issue with pydicom, but in the python bindings for GDCM.
I've run into this a number of times, seems as though some US Dicoms (particularly from the Philips EPIQ CVx) are produced with jpeg compression, but are invalid. In this case I get an error trying to decompress with nearly every library I've used (dcmtk, pylibjpeg, gdcm, etc.)
The problem is just doing
dcm = dcmread('<file>')
anddcm.decompress()
wth GDCM installed silently fails. GDCM seems to print to stderr:without returning anything in a meaningful way that the python code can detect and raise an error from this.
The resultant
pixel_array
is simply all 0's. The best workaround I've found is to just raise an error myself in this case:but I'm curious if anyone has a better way to tell when that fails. Also apologies I don't have any deidentified data I can share for this. I will try to de-identify some.
Beta Was this translation helpful? Give feedback.
All reactions