Learn R Programming

freesurferformats (version 1.1.0)

write.analyze: Write data to a file in ANALYZE 7.5 format.

Description

Write an array or vector to the two files that make up an ANALYZE 7.5 image: a 348 byte header (<base>.hdr) and the raw voxel data in a separate file (<base>.img).

Usage

write.analyze(filepath, analyzedata, analyzeheader = NULL, ...)

Value

invisible named list with the entries header (the header that was written) and data (the data that was written). Use these to check what the function did with your input, they reflect the values that ended up in the file, e.g. values that had to be converted to the data type stated in the header.

Arguments

filepath

character string, the path of the output files. It must end with .hdr or .img (optionally followed by .gz), or contain no extension at all, in which case the two file names are derived from it by appending .hdr and .img. See analyze.pair.files.

analyzedata

array of numeric (integer or double) data, can have up to 7 dimensions. See analyzeheader.for.data for how the data type is chosen, and note that the data type and the number of bits per value in the header have to match the data, otherwise the file is not readable.

analyzeheader

optional ANALYZE 7.5 header that is suitable for the passed analyzedata, see analyzeheader.for.data and analyzeheader.template. If not given, one is generated from the data, with all other fields set to the defaults of the format, i.e. the voxel sizes in pix_dim will be zero and you most likely want to set them.

...

additional parameters passed to analyzeheader.for.data. Only used if analyzeheader is NULL.

See Also

read.analyze.header, analyzeheader.for.data

Examples

Run this code
outfiles <- tempfile()
data <- array(1:24, dim = c(4, 3, 2))
analyzeheader <- analyzeheader.for.data(data)
analyzeheader$pix_dim <- c(1., 1.5, 1.5, 2., 0., 0., 0., 0.)
write.analyze(outfiles, data, analyzeheader)
vol <- read.fs.volume.analyze(outfiles, with_header = TRUE)
vol$header$pix_dim

Run the code above in your browser using DataLab