Learn R Programming

MRIaggr (version 1.1.5)

readMRI: Read an image file

Description

Read an image file and convert it into an array.

Usage

readMRI(filename, format, na.value = 0, what = "numeric", size = "NA_integer_", dimensions = NULL, SPM = FALSE, reorient = FALSE, flipud = FALSE)

Arguments

filename
the file name of the image file. character. REQUIRED.
format
the format of the image file. Can be "raw.gz", "analyze", "nifti" or "dicom". REQUIRED.
na.value
the value with which NA values are replaced. numeric or NA.
what
an object whose mode will give the mode of the vector to be read, or a character vector of length one describing the mode: one of "numeric", "double", "integer", "int", "logical", "complex", "character", "raw". Only active if format equals rawb.gz.
size
the number of bytes per element in the byte stream. integer. See the documentation of the writeBin function for more details.
dimensions
the number of bytes per element in the byte stream. The default, NA_integer_, uses the natural size. Size changing is not supported for raw and complex vectors. Only active if format equals rawb.gz.
SPM
is a logical variable (default = FALSE) that forces the voxel data values to be rescaled using the funused1 ANALYZE header field. This is an undocumented convention of ANALYZE files processed using the Statistical Parametric Mapping (SPM) software. Only active if format equals analyse.
reorient
is a logical variable (default = TRUE) that enforces Qform/Sform transformations. Only active if format equals nifti.
flipud
is a logical variable for vertical flipping of the image (default is TRUE). Only active if format equals dicom.

Value

A nifti object if format="nifit", an anlz object if format="analyse" and else an array.

Details

This function requires to have installed the oro.nifti package to work if argument format is set to "analyze" or "nifti". It requires to have installed the oro.dicom package to work if argument format is set to dicom.

ARGUMENTS : filename argument corresponds to:

  • the con argument of the base::readBin function.
  • the fname argument of the oro.nifti::readANALYZE function. It should be a pathname to .img or .hdr files without the suffix.
  • the fname argument of the oro.nifti::readNIfTI function.
  • the fname argument of the oro.dicom::readDICOMFile function. It should be the file name with suffix.

The what and dimensions correspond to the what and size argument of the base::readBin function. The SPM corresponds to the SPM argument of the oro.nifti::readANALYZE function. The reorient corresponds to the reorient argument of the oro.nifti::readNIfTI function. The flipud corresponds to the flipud argument of the oro.dicom::readDICOMFile function.

FUNCTION : This function is a copy of the readMRI function of the mritc package. It calls readANALYZE of the oro.nifti package to read analyze files, readNIfTI of the oro.nifti package to read NIFTI files, readDICOMFile of the oro.dicom package to read dicom files and readBin of the base package to read rawb.gz.

Examples

Run this code
## load a NIFTI file
path.Pat1 <- system.file(file.path("nifti"), package = "MRIaggr")
nifti.Pat1_TTP_t0 <- readMRI(file.path(path.Pat1, "TTP_t0"), format = "nifti")
dim(nifti.Pat1_TTP_t0)

## Not run: 
# ## load an analyse file (example of oro.nifti::readANALYZE)
# path.Pat2 <- system.file("anlz", package = "oro.nifti")
# analyse.avg <- readMRI(file.path(path.Pat2, "avg152T1"), format = "analyze")
# graphics::image(analyse.avg[,,45,1])
# 
# ### load a NIFTI file (example of oro.nifti::readNIfTI)
# path.Pat3 <- system.file("nifti", package = "oro.nifti")
# nifti.ffd <- readMRI(file.path(path.Pat3, "filtered_func_data"), format = "nifti")
# graphics::image(nifti.ffd[,,10,32])
# 
# ## load a dicom file (examples of oro.dicom::readDICOMFile)
# path.Pat4 <- system.file("dcm", package = "oro.dicom")
# dicom.Abdo <- readMRI(file.path(path.Pat4,"Abdo.dcm"), format = "dicom")
# graphics::image(dicom.Abdo[[2]], col = grey(0:64/64), axes = FALSE, xlab = "", ylab = "",
#                 main = "Abdo.dcm")
# ## End(Not run)

Run the code above in your browser using DataLab