Learn R Programming

MRIaggr (version 1.1.5)

writeMRI: Write an image file

Description

Write an image file from an array.

Usage

writeMRI(data, filename, format, gzipped = TRUE, verbose = optionsMRIaggr("verbose"), size = "NA_integer_")

Arguments

data
the data to export. three dimensional array. REQUIRED.
filename
the name of the image file. character. REQUIRED.
format
the format of the image file. Can be "raw.gz", "analyze", "nifti" or "dicom". REQUIRED.
size
the number of bytes per element in the byte stream. integer. See the documentation of the writeBin function for more details.
gzipped
is a character string that enables exportation of compressed (.gz) files.
verbose
is a logical variable that allows text-based feedback during execution of the function.

Value

None.

Details

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

ARGUMENTS : file argument corresponds to:

  • the con argument of the base::readBin function.
  • the filename argument of the oro.nifti::readANALYZE function. It should be a pathname to .img or .hdr files without the suffix.
  • the filename argument of the oro.nifti::readNIfTI function.

FUNCTION : This function is a copy of the writeMRI function of the mritc package. It calls writeANALYZE of the oro.nifti package to write analyze files, writeNIfTI of the oro.nifti package to write NIFTI files, and writeBin of the base package to write rawb.gz.

Examples

Run this code
set.seed(10)
X <- rnorm(1000)

## Not run: 
# writeMRI(array(X, c(10,10,10)), filename = "test", format = "nifti", verbose = TRUE)
# # range(array(X, c(10,10,10)) - readMRI("test", format = "nifti")[])
# 
# writeMRI(array(X, c(10,10,10)), filename = "test", format = "analyze", verbose = TRUE)
# # range(array(X, c(10,10,10)) - readMRI("test", format = "analyze")[])
# 
# writeMRI(array(X, c(10,10,10)) , filename = "test", format = "rawb.gz", verbose = TRUE, 
#          size = "NA_integer_")
# # range(array(X, c(10,10,10)) - readMRI("test",
# #       format = "rawb.gz", size = "NA_integer_", dim = c(10,10,10)))
# ## End(Not run)

Run the code above in your browser using DataLab