20 September 2014

Using the Debug Option in readDICOMfile()

Some recent activity in stackoverflow was brought to my attention.  Specifically, several questions were raised with reading files into R using readDICOMFile() in the oro.dicom package. The questions did highlight some inadequacies in the code, and I would like to thank the person who brought these issues to the surface.  Some of the errors that occurred were due to the fact that the files are not valid DICOM files, they were created in the early 1990s around the same time that the DICOM Standard was established. 

The result of these questions is twofold
  1. I have modified some of the code to overcome difficiencies that were highlighted.  These modifications will be available in the next release of oro.dicom (0.4.2). 
  2. I would like to raise the profile of a useful option in readDICOMFile(), the debug = TRUE input parameter.  
Let's take a closer look at "debugging" the header information in DICOM files.   The file of interest CR-MONO1-10-chest.dcm is available for download.  Note, you will have to uncompress this file before reading it.  It is not necessary to rename it with a ".dcm" extension, but it looks nicer.


The first attempt at reading this file on line #2 fails.  The error message is very informative, bytes 129-132 do not contain the characters DICM which is part of the DICOM Standard.  So... it's safe to assume that this file is not a valid DICOM file.  Delving further we turn on the debugging option (line #4) and are able to see what the first 128 bytes, which are skipped by default as part of the DICOM Standard, look like.  They obviously contain information.  By setting skipFirst128=FALSE and DICM=FALSE (line #13) we can override the default settings are start reading information from the first set of bytes.  This does the trick and with the debugging option turned on every field from the header is displayed.  No errors have occurred, so we can display the image data from this file (line #40) below.