DICOM images crash ImageMagick

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply

DICOM images crash ImageMagick

Post by mclark » 2007-03-08T11:57:08-07:00

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):
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

User avatar
Site Admin
Posts: 10791
Joined: 2003-05-31T11:32:55-07:00

Re: DICOM images crash ImageMagick

Post by magick » 2007-03-08T19:49:53-07:00

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

Post by mclark » 2008-05-30T13:02:56-07:00

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

Post by mclark » 2008-05-31T05:25:19-07:00

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:
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:

A second problem file is here:
The symptom is that the file shows up black, whereas the DICOM viewers show a full x-ray. Here is the ImageMagick conversion result:

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

Post Reply