Write an fs.volume instance to a file in MGH, MGZ or NIFTI v1 format.
Source:R/write_fs_volume.R
write.fs.volume.RdWrite brain volume data to a file. The format is determined from the file extension of filepath.
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.
- fs_vol
an
fs.volumeinstance, as returned byread.fs.volumewith parameterwith_header=TRUE.
Note
When writing NIFTI files, this function uses nii1header.for.mgh to compute a NIFTI v1 header from the MGH header information.
Examples
if (FALSE) { # \dontrun{
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)
} # }