Monday, July 24, 2017

How to read DICOM in R with oro.dicom?

The steps are as follows (require Internet connectivity).

  • Right-click at R icon and select Run as Administrator.
  • From Packages drop down menu select Install package(s)...
  • Select oro.dicom, oro.nifti, and oro.pet from packages and press OK button
  • Wait installation to finish successfully
Screenshots of steps are as follows. 


The following lines appear after successful installation.

package ‘Rcpp’ successfully unpacked and MD5 sums checked

package ‘bitops’ successfully unpacked and MD5 sums checked
package ‘abind’ successfully unpacked and MD5 sums checked
package ‘RNifti’ successfully unpacked and MD5 sums checked
package ‘oro.dicom’ successfully unpacked and MD5 sums checked
package ‘oro.nifti’ successfully unpacked and MD5 sums checked
package ‘oro.pet’ successfully unpacked and MD5 sums checked

Few commands are executed in R from Using oro.dicom PDF file from website https://cran.r-project.org/web/packages/oro.dicom/index.html. The Abdo.dcm file is in r-release oro.dicom Windows binaries zip archive.  

getwd()
library(oro.dicom)
fname <- system.file(file.path("dcm", "Abdo.dcm"), package="oro.dicom")
abdo <- readDICOMFile(fname)
names(abdo)
head(abdo$hdr)
tail(abdo$hdr)
extractHeader(abdo$hdr, "BitsAllocated")
extractHeader(abdo$hdr, "Rows")
extractHeader(abdo$hdr, "Columns")
image(t(abdo$img), col=grey(0:64/64), axes=FALSE, xlab="", ylab="")

The output of last command is pasted below.


I have encountered error when working with .dcm images provided in MATLAB. Following error message appears on execution of commands in R.

> fname <- system.file(file.path("dcm", "knee1.dcm"), package="oro.dicom")
> abdo <- readDICOMFile(fname)
Error in readBin(fname, "raw", n = as.integer(fsize), endian = endian) : 
  can only read from a binary connection 

Still working on...

Citation from source:
Brandon Whitcher, Volker J. Schmid, Andrew Thornton (2011). Working with the DICOM and NIfTI Data Standards in R. Journal of Statistical Software, 44(6), 1-28. URL http://www.jstatsoft.org/v44/i06/.




No comments:

Post a Comment