Skip to main content.
Monday, November 21st, 2005

Working with DICOM Files

I was having problems working with digital files that came with my PET scan. A little research revealed the existence of the DICOM standard for medical image files, and I found many free DICOM image viewers, but although I downloaded at least four different viewers, I couldn’t open any of the files on the cd I got. Most of the files did not have extensions, so I was guessing at which ones were the images, but some of the files that contained useful information when opened with a hex editor showed DICOM standard headers. (My favorite hex editor used to be Hackman, which is really a complete disassembler/reverse engineering suite, but I found a much simpler and faster hex editor function in my PSPad text editor, which I use to write generic code.) I also noticed that several files had JFIF header info after the DICOM headers, and in accordance with the “Quick and Dirty Tricks” section at David Clunie’s site, I stripped off the DICOM header info and should have had a JPEG image file, but none of my viewers, including the regular image programs IrfanView and Gimp, could open these files.

[UPDATE: Found one! Try Medirec – I’m having trouble opening the raw files (don’t know if that’s a problem with the DR Systems files, or the viewer, or me), but by stripping out the header info and saving the result as a *.jpg file, I have a 12-bit greyscale lossy jpeg that I can open in this viewer – in Windows.]

I started reading up on the DICOM standard and the DR Systems compliance document, but that bogged me down pretty quickly. So I sent off an email to David Clunie. With his permission, here’s his answer:

Hi Greg

I took a look at the files that you sent, and there is nothing seriously
wrong with them with respect to anything that might confuse a viewer.

The problem you are having is simply that the images are encoded
using the 12 bit lossy JPEG transfer syntax, and many viewers just
don’t support that. Further, if you extract the JPEG bitstream,
most consumer image viewers won’t support the 12 bit JPEG form
as opposed to the usual 8 bit JPEG form either.

The bottom line is that you either need to use a viewer that
handles the JPEG DICOM transfer syntaxes, or find a way to
have the DR Systems CD creation tool encoded them uncompressed
(even if they were stored in the PACS compressed, which is
likely with that system).

I would also point out that lossy compression of PET images is
probably not cool from the perspective of quantitative PET
measurements (like SUV), though the likely error, if any, would
be very small.

That said, the images are not strictly compliant with the standard,
probably as a result of them being inverted and squeezed into 12
bits rather than 16, but I doubt if that has anything to do with
the problems that you are seeing:

% dciodvfy 196
Warning – Optional Type 2C Conditional Element=<patientposition> Module=<generalseries>
Warning – Unrecognized defined term <ring> for attribute <field of View Shape>
Error – Unrecognized enumerated value <monochrome1> for attribute <photometric Interpretation>
Error – Unrecognized enumerated value <0xc> for attribute <bits Stored>
Error – Unrecognized enumerated value <0xb> for attribute <high Bit>

I suspect that the errors are being introduced by the DR Systems
PACS, and not by the Siemens ECAT system.

If you want me to recommend a particular viewer, I would suggest
Osirix, which does open these images just fine (I tried it), though
you need a Mac to use it. It has nice 3D.

If you want to just uncompress the whole lot so that you view
them with an “ordinary” DICOM viewer, then you could try the
dcunjpeg script from my dicom3tools, which depends on the
presence of the Stanford PVRG JPEG codec, both of which are
available on my web site – but these require a unix system
on which to compile them and may be more trouble than it is


First off, I just wanted to give a big public thanks to David, who responded quickly and was very helpful. I started searching for a free image viewer that could handle the 12-bit lossy JPEGs, but haven’t found one yet. There are some commercial medical image reading programs that start around US$4K (!!!), but that’s a little more than I would be willing to spend. I noted that handling 12-bit images are planned for the Gimp 2.4 version, and I’ll be eagerly waiting for that.

Looks like I’m going to have to get back to working on my Fedora Core 4 installation so I can try David’s uncompression scripts, not to mention completing the build my other computer, which is intended to be a Linux-only box. **Sigh**. Why do I get so many interesting projects building up when I have even less time to spend on them?

Posted by Greg in General Science, Software

1 Comment »

This entry was posted on Monday, November 21st, 2005 at 05:32 PST and is filed under General Science, Software. You can follow any responses to this entry through the comments RSS 2.0 feed. Both comments and pings are currently closed.

One Response to “Working with DICOM Files”

  1. harsha says:

    Greg, I use the PETLinQ viewer and it works well for PET images. Although we normally sell it to customer I’d be happy to let you use it for non-commercial use. write me at if you still need it