Page 1 of 1

DICOM images crash ImageMagick

Posted: 2007-03-08T11:57:08-07:00
by mclark
I've been using ImageMagick to convert from DICOM digital xrays to JPEG format. However, some DICOM files produce a segmentation fault in ImageMagick, whereas the images load correctly in other DICOM viewers (such as K-Pacs).

I traced the problem down to code in string.c that was dereferencing a null pointer. I patched this, but now I receive an "InsufficientImageDataInFile" error (line 2923, coders/dcm.c). I have tried both the built-in Fedora version (6.2.8) and the latest online from source code (6.3.3).

Here are three files that crash ImageMagick (but work in DICOM viewers):
http://www.gorgeswebsites.com/test1.dcm
http://www.gorgeswebsites.com/test2.dcm
http://www.gorgeswebsites.com/test3.dcm
Note: the original file names had "1.2.840.114417.0.UID" format, where UID was a long decimal string. And I can get more images from the same DICOM x-ray machine if testers need them.

Thanks in advance for any assistance here. I wonder if the DICOM format has been extended, but ImageMagick hasn't kept pace.

Matt Clark

Re: DICOM images crash ImageMagick

Posted: 2007-03-08T19:49:53-07:00
by magick
We can reproduce the problem you posted and have a patch to prevent the fault. However, like you, we get the "nsufficient image data" error. It may take us some time to before we can come up with a proper fix for this problem.

Re: DICOM images crash ImageMagick

Posted: 2008-05-30T13:02:56-07:00
by mclark
I recently upgraded to ImageMagick 6.4.1, and several DICOM bugs are still there that crash ImageMagick.

If anyone (including the ImageMagick developers) would like my source code changes to the files "dcm.c" and "jpeg.c", please contact me at mclark at gorgeswebsites.com and I will send you the revised files.

I'm now running into trouble with some new DICOM formats that turn a monochrome image into RED+GREEN. I wonder if there's a new 24-bit JPEG format for monochrome. If anyone has encountered this, please let me know - I'd be happy to share my patches with the open source community.

Re: DICOM images crash ImageMagick

Posted: 2008-05-31T05:25:19-07:00
by mclark
I recently had an offer from "duc" to send him patches - I hope they make their way into the code base!

And for those who like challenges, here are the current DICOM bugs I'm grappling with:

One of my problematic files is here:
http://www.evetdiagnostics.com/magick/test1.dcm
The symptom is that this conversion to JPEG produces an image that is incorrectly colored in red and green:

Code: Select all

convert -delete 1-9999 -compress jpeg -quality 90 test1.dcm test1.dcm.jpg
Here is the incorrect result:
http://www.evetdiagnostics.com/magick/test1.dcm.jpg

A second problem file is here:
http://www.evetdiagnostics.com/magick/test2.dcm
The symptom is that the file shows up black, whereas the DICOM viewers show a full x-ray. Here is the ImageMagick conversion result:
http://www.evetdiagnostics.com/magick/test2.dcm.jpg

I use free DICOM viewers such as K-PACS or XMEDCON and a commercial viewer XSCAN32 to see how the images should appear.

Thank you in advance if anyone has knowledge of how to patch ImageMagick for these problems!

Matt Clark