8

I have some DICOM medical imaging files downloaded from Cancer Imaging Archive. I can convert them from DICOM to several other formats, but as you'll see the conversion isn't working as expected in most cases.

These are the various conversions I've figured out so far:

  • DICOM to netpbm format: dctopgm8 000005.dcm 000005.pbm
  • DICOM to pnm format: dctopnm -byteorder little 000005.dcm 000005.pnm
  • DICOM to png format: dcm2pnm +on 000005.dcm 000005.png
  • DICOM to png format (via ImageMagick): convert 000005.dcm 000005.png

Of those, the .pbm is the only one that seems to give great results. It looks like this:

pbm file

The .pnm looks like this, which is not quite an inverse image, but somehow looks wrong:

pnm file

And both of the .png conversions look like this, which is a very washed out image, perhaps due to problems with an alpha channel, gamma, or...?

png file

The problem is I need these to be in PNG, not PBM. And while I could add an additional conversion from PBM to PNG, I'd rather call convert only once and do the full conversion in a single command.

Anyone know what parameters I might be missing in the calls to dcm2pnm or ImageMagick's convert to get the images looking as expected?


Edit: including a sample .dcm image: 000005.dcm

10
  • 2
    Why not do it in two steps: dctopgm8 000005.dcm 000005.pbm and convert 000005.pbm 000005.png ? Oct 30, 2019 at 9:43
  • @LjmDullaart Because I'd rather understand what parameters I'm missing so I can do the conversion in a single step.
    – Stéphane
    Oct 30, 2019 at 9:45
  • I don't really get what the problem is. Your last command is a single conversion command. The other commands, if still necessary, highlight what needs to be done. For a single command dcmj2pnm seems to provide what you're asking for?
    – Seth
    Oct 30, 2019 at 9:53
  • @Seth I would like to convert the DICOM to PNG format with a single conversion command.
    – Stéphane
    Oct 30, 2019 at 9:55
  • @Moab No, as you can see above, that technique does not work. The images are not converted correctly. The only one that seems to work correctly is the .pbm, but what I need is .png or .jpg.
    – Stéphane
    Oct 30, 2019 at 14:23

4 Answers 4

3

It looks like you're trying to convert at 16-bit image to 8-bit. It looks like a CT image, where pixel values typically go from -1000 (air) to 0 (water) to 3000 (dense bone).

I'm guessing the PBM program is mapping the 16-bit to 8-bit by rescaling the pixel values. It looks like the PNM version is only taking the lower 8-bits and ignoring the upper 8. The PNG image probably has the entire 16 bit data, since PNG supports it, but your viewer displays only the upper 8-bits, ignoring the lower 8.

You need to rescale the pixel intensities to 0-255 from -32768-32767 (or 0 to 63356 if you view them as unsigned 16 bit ints).

You can do this using SimpleITK in Python like so:

import SimpleITK as sitk

img = sitk.ReadImage("000005.dcm")
# rescale intensity range from [-1000,1000] to [0,255]
img = sitk.IntensityWindowing(img, -1000, 1000, 0, 255)
# convert 16-bit pixels to 8-bit
img = sitk.Cast(img, sitk.sitkUInt8)

sitk.WriteImage(img, "000005.png")
0

There has been several alternate answers, and while you've tagged it as Linux and ImageMagick, you never said in the question itself that you're restricted to that. So in any case, IrfanView does support DICOM, and it also has a batch mode via File / Batch Conversion/Rename (or just pressing 'B'). I just successfully converted around 150 .dcm files to .png using it.

It's free, and while it's Windows-only, it works perfectly fine from under Wine. Just make sure to install the plugin bundle, which provides DICOM support itself.

-1

If you can use GIMP https://www.gimp.org/ you can easily open image and export to other formats.

Why it didnt work with your converter is another question. I had same problem (not with this format or converter) that converter expected different bitness that sources image had (8-bit vs. 16-bit)

3
  • 3
    No, GIMP wont work, I have thousands of images I need to convert. And when I use GIMP on DICOM files, it opens them like the .pnm conversion sample I posted in the question, where the images are strangely inverted.
    – Stéphane
    Oct 30, 2019 at 10:33
  • I opened your example in gimp and I think it is working prntscr.com/pq2s30 I also think GIMP can be used for batch convert but I am not 100% on this.
    – Rok
    Oct 30, 2019 at 10:42
  • No, that image is not correct. See the top of my question. It should look like that first image, while in gimp it looks like the 2nd image.
    – Stéphane
    Oct 30, 2019 at 10:50
-1

If you're on or have access to a Mac, https://DICOM-converter.com is a free utility that does drag and drop conversion of files or complete folders structures, to JPEG, PNG, (animated)-GIF, MOV, or MP4.

3
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    May 24, 2022 at 18:18
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Toto
    May 24, 2022 at 18:33
  • I think in this case the link is fine: the OP isn't looking for an explanation why conversion does not work; but for a way how to convert multiple files at once, to png.
    – Wouter
    May 24, 2022 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .