Using the Debug Option in readDICOMfile()

[This article was first published on Rigorous Analytics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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. 

To leave a comment for the author, please follow the link and comment on their blog: Rigorous Analytics.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)