InputOutput-readMRI: Read an image file

Description Usage Arguments Details Value Examples

Description

Read an image file and convert it into an array.

Usage

1
2
3
readMRI(filename, format = NULL, na.value = 0, 
		what = "numeric", size = "NA_integer_", dimensions = NULL, 
		SPM = FALSE, reorient = FALSE, flipud = FALSE, recover.header = FALSE, verbose = FALSE)

Arguments

filename

the file name of the image file (including the filename extension). character. REQUIRED.

format

the format of the image file. Can be "raw.gz", "analyze", "nifti" or "dicom".

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.

recover.header

for analyse files, if only one of the .hdr file and the .img file is compressed, should they be copied to a temporary directory, decompressed and loaded. logical.

verbose

should the execution of the function be traced ? logical.

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 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.

Value

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
## load a NIFTI file
path.Pat1 <- system.file(file.path("nifti"), package = "MRIaggr")
nifti.Pat1_TTP_t0 <- readMRI(file.path(path.Pat1, "TTP_t0.nii"))
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.img.gz"))
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.nii.gz"))
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"))
graphics::image(dicom.Abdo[[2]], col = grey(0:64/64), axes = FALSE, xlab = "", ylab = "",
                main = "Abdo.dcm")

## load a rawb.gz file
path.Pat4 <- system.file(file.path("extdata"), package = "mritc")
rawb.Pat4 <- readMRI(file.path(path.Pat4, "t1.rawb.gz"), dimensions = c(91,109,91))
dim(rawb.Pat4)

## End(Not run)

bozenne/MRIaggr documentation built on May 13, 2019, 1:39 a.m.