View source: R/write_analyze.R
| write.analyze | R Documentation |
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).
write.analyze(filepath, analyzedata, analyzeheader = NULL, ...)
filepath |
character string, the path of the output files. It must end with |
analyzedata |
array of numeric (integer or double) data, can have up to 7 dimensions. See
|
analyzeheader |
optional ANALYZE 7.5 header that is suitable for the passed |
... |
additional parameters passed to |
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.
ANALYZE 7.5 cannot store a transformation matrix, and the format does not even define the direction of the
voxel axes in world space. This writer therefore cannot write the geometry of an image: if you have a volume
with a known vox2ras_matrix and you want to keep it, write a NIFTI v1 file with
write.nifti1 instead (either a single file, or a .hdr/.img pair by setting the header magic
to 'ni1', which is what write.fs.volume does for such file names). If you know that the data
will be read by SPM or FreeSurfer, you can store the image origin in the spm_origin field of the header, see
read.analyze.header.
Note that tools differ in how they recognize the format. FreeSurfer's mri_convert, for example, does not
infer the ANALYZE format from the .hdr file extension and reports 'cannot determine file type' unless the
input type is given explicitly: mri_convert -it analyze -ot mgz vol.hdr vol.mgz works, mri_convert -ot mgz vol.hdr vol.mgz does not. The header written by this function is the one FreeSurfer itself writes for
-ot analyze, so this is a limitation of the reader, not of the file.
read.analyze.header, analyzeheader.for.data
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.