DICOM incorrectly converts background color

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
purrquay
Posts: 12
Joined: 2011-03-23T17:09:45-07:00
Authentication code: 8675308

DICOM incorrectly converts background color

Post by purrquay »

I have a number of DICOM files (see this one for an example) that I am converting to PNG format. These files have an alpha channel and a white background. The converted PNG files, on the other hand, have black backgrounds.

Using ImageMagick 6.6.9-6 2011-04-14 Q16, I simply ran "convert 4026778101315.DIC 4026778101315.PNG".
Then I did "identify.exe -verbose " on both files. The DICOM file was reported as having "Background color: white", and the PNG file "Background color: black".

Here is what the above DICOM file looks like. Notice the "TR" in the bottom right, along with the extra bright white tooth surfaces.
Image

And this is what the corresponding PNG file looks like:
Image

Please help. I've tried setting the background colour explicitly, but it has no effect on the resulting PNG image.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: DICOM incorrectly converts background color

Post by glennrp »

The alpha channel seems to be gone before it gets to the
PNG encoder. Converting to TXT or MIFF format also yields an
opaque grayscale image. "identify -verbose *.DIC" says the input
file is opaque grayscale.

The reported background color indeed does change from
white to black, but that seems to be irrelevant. I'll look into
why that happened.
purrquay
Posts: 12
Joined: 2011-03-23T17:09:45-07:00
Authentication code: 8675308

Re: DICOM incorrectly converts background color

Post by purrquay »

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

Re: DICOM incorrectly converts background color

Post by magick »

Try this command:
  • convert -define dcm:display-range=reset 4026778101315.DIC 4026778101315.doc
If that fails, you made need a recent patch that will be available in ImageMagick 6.6.9-7 Beta available sometime tomorrow.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: DICOM incorrectly converts background color

Post by glennrp »

The background color issue with PNG grayscale output is fixed in SVN revision 4344 (IM-6.6.9-7).
purrquay
Posts: 12
Joined: 2011-03-23T17:09:45-07:00
Authentication code: 8675308

Re: DICOM incorrectly converts background color

Post by purrquay »

Damn, you guys are quick!

I'll download and test it out.

Thanks muchly again.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: DICOM incorrectly converts background color

Post by anthony »

If you already have downloaded the SVN version, I suggest you get it again now.

I had a re-organisation of the CLI, as part of some steps for a new type of "convert"-like 'scripting' command (for the furture of IM v7 - name undecided) and it left the SVN beta version in a bad start (draw settings were failling). I learned from this made some backups (for future work) and backed out my change. Basically the change is too radical for IMv6 and it was a mistake to check in work toward that change at this time.

As such I suggest you 'update' or 'checkout' the SVN again now. --- Sorry :?


ASIDE...

AT this point in time I will be concentrating more on simle improvements and bug fixes, as I study 'shells' for programming methodology that may improve CLI and scripting capabilities of IM. IM really could use some more programmers. People who are willing to get go it and give it a try. It is amazing what you can do when you try.

FYI.. there is a new 'Inverse' sparse-color addition. See
http://www.imagemagick.org/Usage/canvas/#inverse
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
purrquay
Posts: 12
Joined: 2011-03-23T17:09:45-07:00
Authentication code: 8675308

Re: DICOM incorrectly converts background color

Post by purrquay »

Unfortunately, build 6.6.9-7 still produces the same incorrect result on the sample DICOM image (see the original post) :(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: DICOM incorrectly converts background color

Post by fmw42 »

I just downloaded your original image and displayed it in IM 6.6.9.7 Q16 Mac OSX Tiger.

display 4026778101315.DIC

and it has the same dark pattern as your converted image. No other application that I have will even open it.
purrquay
Posts: 12
Joined: 2011-03-23T17:09:45-07:00
Authentication code: 8675308

Re: DICOM incorrectly converts background color

Post by purrquay »

ImageMagick's own display tool obviously has the same behaviour as the convert tool, since they use the same codec.

Try (X)MedCon instead. Sante DICOM Viewer and mDicom also display it correctly.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: DICOM incorrectly converts background color

Post by magick »

ImageMagick can display / convert the image correctly. Simply add -define dcm:display-range=reset to you command line. Its required to reset the window width encoded within the image.
purrquay
Posts: 12
Joined: 2011-03-23T17:09:45-07:00
Authentication code: 8675308

Re: DICOM incorrectly converts background color

Post by purrquay »

Thanks. That did the trick.
Post Reply