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. 

29 December 2013

oro.dicom 0.4.0

The R package oro.dicom contains data input/output functions for medical imaging data that conform to the Digital Imaging and Communications in Medicine (DICOM) standard, part of the Rigorous Analytics bundle.

The latest version of oro.dicom (0.4.0) contains a substantial update:

  • The function subroutines of readDICOMFile() have been re-written from scratch.  
    • The entire DICOM file is read into R using readBin(what = "raw") and parsed in a recursive fashion.  That is, the DICOM header information is processed in the (group, element) doublets until a sequence header is found.  Once a sequence header is found, then the subroutine is called again... and so on and so forth... until the entire DICOM header is parsed.  This has reduced the total number of lines of code and, I believe, made the process more easily digestible.  
    • Assuming a PixelData or SpectroscopyData field is present, the subsequent bytes will be read into a separate R data structure.  
Other modifications have taken place, one in particular is the ability of oro.dicom to process spectroscopy data in the DICOM format.  I have had requests for this package to write DICOM files as output, but unfortunately I have not found the time myself to add this capability.

The revised code has been tested against a collection of DICOM files and works well.  However, only time will tell if the modifications work against the wide variety of DICOM headers one can find.  If you have DICOM data that you would like to contribute to the test suite for oro.dicom, please contact me at rigorousanalytics@gmail.com or post messages on this blog.

oro.nifti 0.4.0

Okay, so it's been quite a while since I provided an entry associated with oro.nifti.  That doesn't mean things haven't moved on... they have.  Let's just say I've been occupied.  One of the biggest changes to oro.nifti recently has been the "audit trail" is not turned off by default.  If you want to take advantage of this feature you must explicitly turn it on using the commands

R> options("niftiAuditTrail" = TRUE)
R> enableAuditTrail()

This modification was a consequence of severing the dependence on the XML package, since it was only required if one wanted to keep track of the operations performed during the data analysis (it is now only suggested).  Please see the vignette for more information about the audit trail feature.  Otherwise, minor improvements have been made and updates so that the package works with the most current version of R (3.0.2 at the time of this blog entry).  

Please use the mailing list at r-forge.r-project.org or contact rigorousanalytics@gmail.com with any suggestions.


29 December 2011

Magnetic Resonance Imaging in R

Volume 44 of the Journal of Statistical Software was published in October 2011.  The special volume on “Magnetic Resonance Imaging in R” features articles and packages related to a variety of imaging modalities:
The papers describe the methodology, software implementation and provide comprehensive examples and data.  A complete list of the issues is:




27 December 2011

oro.nifti 0.3.1

The  package oro.nifti contains functions for the input/output and visualization of medical imaging data that follow either the ANALYZE, NIfTI or AFNI formats.  This package is part of the Rigorous Analytics bundle.

Lightbox display of functional MRI "resting-state" acquisition using image().  The axial plane is used by default.

Lightbox display of functional MRI "resting-state" acquisition using image(, plane="coronal").

Llightbox display of functional MRI "resting-state" acquisition using image(, plane="sagittal").

Orthographic display of functional MRI "resting-state" acquisition using orthographic().

The latest version of oro.nifti (0.3.1) contains a substantial number of updates:
  • Visualization of NIfTI and ANALYZE S4 objects
    • Aspect ratio is now respected in the overloaded image() function for "nifti" and "anlz" class objects.
    • The plane of acquisition (axial, coronal, sagittal) may now be specified by the user.
    • Min/max values of the data are properly interrogated if cal.min/cal.max or glmin/glmax are not specified.
  • Added accessor/replacement functions for cal.min and cal.max NIfTI metadata fields.
  • Fixed bug in pixdim<- replacement function, should work now.
  • Fixed bug in writeNIfTI so that FSLView can correctly identify the min/max values.
  • Better treatment of Qform and Sform information.
Please use the mailing list at R-Forge or contact rigorousanalytics@googlemail.com with any suggestions.

oro.dicom 0.3.3

The R package oro.dicom contains data input/output functions for medical imaging data that conform to the Digital Imaging and Communications in Medicine (DICOM) standard, part of the Rigorous Analytics bundle.


The latest version of oro.dicom (0.3.3) contains a substantial number of updates:
  • dicomInfo = readDICOMFile and dicomSeparate = readDICOM, but the old function calls still exist for now to smooth the transition.
    • readDICOM now accepts a single file as input, creating the list-of-lists structure with one element in $hdr and $img.
  • Modest speed improvements in readDICOMFile from a thorough use of Rprof().
  • Added txtProgressBar() to readDICOM and dicomTable.
  • Sub-routines used in readDICOM have been made private.
  • Added default sform information to dicom2nifti.
  • Miscellaneous bug fixes.
  • Added "instance" input parameter to create4D so the user can decide whether or not to access the "InstanceNumber" DICOM header field for slice ordering.
Please use the mailing list at R-Forge or contact rigorousanalytics@googlemail.com with any suggestions.

21 December 2010

oro.nifti 0.2.4

The R package oro.nifti contains functions for the input/output and visualization of medical imaging data that follow either the ANALYZE, NIfTI or AFNI formats.  This package is part of the Rigorous Analytics bundle.

Orthographic display of structural MRI acquisition from the AFNI data collection (afni_anat1+orig.BRIK).

 
The latest version of oro.nifti (0.2.4) has been submitted to CRAN and is available on R-Forge now.  New features include:
  • Read/write/visualize AFNI data (thanks to contributions by K. Tabelow)
  • writeANALZE and writeNIfTI are now S4 generic functions (suggested by K. Tabelow)
  • Conversion in both directions between fmridata-S3 (from the fmri package) and nifti-S4 classes.
  • Fixed bugs in translateCoordinate (thanks to R. Heckemann)
Please use the mailing list for any suggestions or contact rigorousanalytics@gmail.com.