These functions write an image to NIfTI-1, NIfTI-2 or ANALYZE-7.5 format, using the standard NIfTI C library.
writeNifti(image, file, template = NULL, datatype = "auto", version = 1,
compression = 6)writeAnalyze(image, file, template = NULL, datatype = "auto",
compression = 6)
An invisible, named character vector giving the image and header file names written to.
An image, in any acceptable form (see asNifti
).
A character string containing a file name. If this has no file
extension suffix, or ends with "nii"
, the single-file NIfTI format
is used; if the suffix is "nii.gz"
, the compressed single-file
format is used; if the suffix is "hdr"
or "img"
, the NIfTI
pair two-file format is used; if it's "hdr.gz"
or "img.gz"
,
the compressed pair format is used. If any other extension is present it
will be ignored, and ".nii"
appended.
An optional template object to derive NIfTI properties
from. Passed to asNifti
if image
is an array.
The NIfTI datatype to use when writing the data out. The
default, "auto"
uses the R type or, for internal images, the
original datatype. Other possibilities are "float"
, "int16"
,
etc., which may be preferred to reduce file size. However, no checks are
done to ensure that the coercion maintains precision.
An integer (1 or 2) giving the NIfTI file format version to use. Version 2 is usually only needed for very large images or where metadata needs to be stored with high precision. The types available for storing the pixel data are the same in both cases.
The gzip compression level to use, an integer between 0 (none) and 9 (maximum). Ignored if an uncompressed format is implied by the requested file name.
Jon Clayden <code@clayden.org>
The NIfTI-1 standard (https://www.nitrc.org/docman/view.php/26/64/nifti1.h).
readNifti
, asNifti
if (FALSE) writeNifti(im, "image.nii.gz", datatype="float")
Run the code above in your browser using DataLab