2

The dcmcjpeg tool from the dcmtk package (sudo apt-get install dcmtk) is supposed to convert DICOM image files to JPEG.

But I suspect it still wraps the image in a DICOM container, because when I try, I get this:

> file 000010.*
000010.dcm: DICOM medical imaging data

> md5sum 000010.*
a64dee7fa9c9fb383c9aec833006f161  000010.dcm

> dcmcjpeg --verbose --encode-extended --quality 75 --huffman-optimize --bits-force-8 --monochrome 000010.dcm 000010.jpg
I: reading input file 000010.dcm
I: Convert DICOM file to compressed transfer syntax
I: Output transfer syntax JPEG Extended, Process 2+4 can be written
I: creating output file 000010.jpg
I: conversion successful

> file 000010.*
000010.dcm: DICOM medical imaging data
000010.jpg: DICOM medical imaging data

> md5sum 000010.*
a64dee7fa9c9fb383c9aec833006f161  000010.dcm
c3019b54640179805ab3912414b97936  000010.jpg

How can I fully extract the image from a DICOM file and convert it to a common format such as JPEG or PNG?

1
  • I've also asked a similar question about converting from DICOM to PNG. If the questions are too similar, then this one can be closed as I'd prefer to know how to convert to PNG versus JPG. superuser.com/questions/1497370/…
    – Stéphane
    Commented Oct 30, 2019 at 9:39

2 Answers 2

5

Please use the tool dcmj2pnm:

This tool converts DICOM images to PGM/PPM, PNG, TIFF, JPEG or BMP

Here is a usage sample: dcmj2pnm --write-jpeg --min-max-window ST1-SE1.dcm foot-xray.jpg

Use the option " --min-max-window" for calculating the VOI window using min-max algorithm

HTH

3
  • I tried the dcmj2pnm tool. Similar results to the other tools discussed in that other linked question. It doesn't seem to correctly convert the image, though the --min-max-window parameter does improve things.
    – Stéphane
    Commented Nov 5, 2019 at 22:02
  • In fact, dcmj2pnm does exactly what you want: read a DICOM image and render its pixel data to a bitmap that is either stored as a PNG or JPEG image file. If the output is not as expected, you were certainly missing one (or more) of the available options. See man page (or --help output) for details. Commented Oct 30, 2020 at 9:58
  • I recommend converting it to TIFF instead and specifying uncompressed, to get the best image quality settings possible. Use --write-tiff and --compr-none.
    – rlittles
    Commented Mar 30, 2022 at 6:46
2

Just a little more info for those trying to run this in Linux:

Install

sudo apt-get install dcmtk

DICOM Information

dcmj2pnm --image-info --no-output --verbose image.dcm

Extract all images

dcmj2pnm --write-png image.dcm ./output --all-frames
1
  • dcmj2pnm --write-jpeg worked for me to convert from a .dcm image to a .jpg. Although the resulting jpegs were missing the metadata from the DICOM (like date and other textual information). Bummer. Commented Jun 2, 2023 at 14:50

You must log in to answer this question.

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