Converting X-Ray Images into JPEG

While out scouting a rapid on the North Fork of the Stanislaus in California I decided to take a closer look at the rocks down below by flinging my body rapidly face first into them.  Some people might have mistaken this action for slipping.  While doing so I twisted my middle finger and it has been swollen ever since.  Hasn’t bother me much but my doctor thought I should get it x-rayed to be safe.

One-finger salute X-Ray. There was no fracture.

This is how I came across a CD full of hand x-rays.  Now most people would use a standardized format that everyone can understand.  Being the medical field they have their own format to encapsulate standard formats and make them unreadable.  All of these files had a ‘dcm’ extension, which means they contain DICOM image files.  A quick search online turned up several suggestions on how to convert the file and none of them worked.

Using the unix “convert” command might have worked, but there seems to be problems if a loss less JPEG is encapsulated in the DICOM file.  A bit more searching and I found out about dcmtk which is an open source project for reading and modifying these files.  It provides several functions, such “dcm2pdf” or “dcmdjpeg” but these won’t create a jpeg directly.  The command ‘dcmdump’ shows information on the file and verified that it was in fact in lossless jpeg format.  To extract a readable image from the DICOM file, follow these steps in Linux:

  1. install dcptk
  2. dcmdump INPUT.dcm
  3. dcmdjpeg INPUT.dcm OUTPUT.dcm
  4. dcmp2pgm OUTPUT.dcm image.pgm

The second step verifies which image format is encapsulated and is used to determine which dcmd* command should be invoked.  The third step converts the jpeg encoded DICOM into a standard format DICOM file.  The fourth step converts the DICOM file into a ‘pgm’ file.  The pgm file can be viewed in most graphics program and can be easily converted into a jpeg file.  To the right is one of the extracted x-ray images.

 

Leave a Reply

Your email address will not be published.