Learn R Programming

freesurferformats (version 1.1.0)

write.fs.volume: Write an fs.volume instance to a file in MGH, MGZ or NIFTI v1 format.

Description

Write brain volume data to a file. The format is determined from the file extension of filepath.

Usage

write.fs.volume(filepath, fs_vol)

Arguments

filepath

string. Full path to the output file. The file extension determines the format: '.mgh' or '.mgz' for FreeSurfer MGH/MGZ format, '.nii' or '.nii.gz' for NIFTI v1 format, and '.hdr', '.img', '.hdr.gz' or '.img.gz' for a NIFTI v1 pair, i.e. a header file with a separate data file. A pair is written instead of a plain ANALYZE 7.5 file because ANALYZE cannot store the geometry of the volume, see write.analyze if you need real ANALYZE output.

fs_vol

an fs.volume instance, as returned by read.fs.volume with parameter with_header=TRUE.

Examples

Run this code
if (FALSE) {
mgh_file <- system.file("extdata", "brain.mgz",
  package = "freesurferformats",
  mustWork = TRUE
)
fs_vol <- read.fs.volume(mgh_file, with_header = TRUE)
write.fs.volume(tempfile(fileext = ".mgz"), fs_vol)
write.fs.volume(tempfile(fileext = ".nii.gz"), fs_vol)
write.fs.volume(tempfile(fileext = ".hdr"), fs_vol)
}

Run the code above in your browser using DataLab