Skip to main content
Home

Search form

  • Home
  • Calendar
  • People
    • Key Personnel
    • Members
    • Collaborators
  • Grants
  • Papers
  • Blogs
  • Wiki
  • Log In
Home / Reading_Data_R

Reading_Data_R

How to read/write in Neuroimaging Data in R

There are many packages in R that allow you to read in neuroimaging data. Primarily, the format we will be using will be NIfTI. The documentation for R has a lot information here NIfTI files contain all header information, such as image dimensions, pixel resolution, intensity values, scaling factors, etc, is contained in one file. ANALYZE files are similar, which have a .img and .hdr files that contain the image (3D array) and header information, respectively.

Reading in NIfTI

library(oro.nifti)
## Loading required package: bitops
## oro.nifti: Rigorous - NIfTI+ANALYZE+AFNI Input / Output (version = 0.3.9)
img <- readNIfTI("MNI152_T1_2mm_brain.nii.gz")
## Warning: scl_slope = 1 and data must be rescaled.
image(img, z = 40, plot.type = "single")

plot of chunk unnamed-chunk-1

arr <- img@.Data
# writeNIfTI(nifti-object, filename='fileWithoutNii')

The package oro.nifti is (in my opinion) the best reader of NIfTI files because you can store data gzipped as .gz without having to do any work around using gunzip from the R.utils package. The data is stored in slots which can be called using the \@ symbol. Methods should still work by

In order to write a nifti file, you need a nifti object, which you create by using, (guess which function), nifti(array), where array is a 3D array.

library(fmri)
read.NIFTI("file.nii")
write.NIFTI(3-or-4D-array, filename)
library(AnalyzeFMRI)
f.read.nifti.volume("file.nii")
f.write.nifti(3D-array, filename="file.nii")

Reading in DICOM

Also, one format to read in is DICOM, which is a format where each slice is contained within one file. oro.dicom is similar to oro.nifti and has the functions readDICOM for reading an entire DICOM directory and readDICOMFile to read individual DICOM files. One very useful flag: is pixelData=FALSE which will read the header information from the DICOM.

Tags: 
R
neuroimaging
NIFTI
DICOM
image

Navigation

  • Statistical methods
    • General
    • Causal Inference
    • Population ICA
    • PVD
    • Testing
    • Prediction / Machine Learning
    • Computation
    • Visualization
    • Structural PCA
  • Scientific areas of interest
    • Brain imaging - Variability
    • Brain Imaging - Prediction
    • Brain Imaging - Clinical
    • Wearable Computing
    • Biosignals
  • Software & Tutorials
  • Social media
  • Logos

Tags in Tags

brain imaging Cluster DICOM functional data intra class correlation neuroimaging NIFTI Parallel Computing R replication SMART wiki
More
© 2012 smart-stats.org