Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

niftiwrite

Write volume to file using NIfTI format

Syntax

niftiwrite(V,filename)
niftiwrite(V,filename,info)
niftiwrite(V,filename,info,Name,Value)

Description

example

niftiwrite(V,filename) writes the volumetric image data V to a file by using the Neuroimaging Informatics Technology Initiative (NIfTI) format. By default, niftiwrite creates a combined NIfTI file that contains both metadata and volumetric data. niftiwrite names the file filename, adding the .nii file extension. niftiwrite populates the metadata using appropriate default values and volume properties, such as size and data type.

example

niftiwrite(V,filename,info) writes the volumetric data V to a file, including the file metadata from info. If the metadata does not match the image contents and size, niftiwrite returns an error.

niftiwrite(V,filename,info,Name,Value) writes the volumetric data to a file, using options specified in Name,Value pairs.

Examples

collapse all

Load a NIfTI image by using its .nii file name.

V = niftiread('brain.nii');

Filter the image in 3-D by using a 3-by-3 median filter.

V = medfilt3(V);

Write the filtered image to a .nii file, using default header values.

niftiwrite(V,'outbrain.nii');

Read the metadata from a NIfTI file by using its .nii file name.

info = niftiinfo('brain.nii');

Read volumetric data from the file by using the file metadata.

V = niftiread(info);

Edit the Description metadata field of the file.

info.Description = 'Modified using MATLAB R2017b';

Write the volumetric data with the modified metadata to a new .nii file.

niftiwrite(V,'outbrain.nii',info);

Input Arguments

collapse all

Name of NIfTI file, specified as a string scalar or character vector. By default, niftiwrite creates a combined format file that contains both metadata and image data and has the file extension .nii. If you specify the 'Compressed' name-value pair, niftiwrite adds the file extension .nii.gz. If you set the 'Combined' name-value pair to false, then niftiwrite creates two files with the same name and different file extensions. One file contains the metadata associated with the volume and has the file extension .hdr. The other file contains image data and has the file extension .img.

Data Types: char | string

Volumetric data, specified as a numeric array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

File metadata, specified as a structure returned by the niftiinfo function.

Data Types: struct

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: niftiwrite(V,'outbrain.nii','Compressed',true)

collapse all

Type of NIfTI file to create, specified as true or false. If true (the default), niftiwrite creates a single file with the file extension .nii. If false, niftiwrite creates a pair of files with the same name but with different file extensions: .hdr for the file containing metadata, and .img for the file containing the volumetric data.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Compress image data, specified as true or false. If 'Compressed' is true, then niftiwrite generates compressed files, using gzip, with the file name extension .gz.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Endianness of the data, specified as 'little', to indicate little-endian format (default) or 'big', to indicate big-endian format.

Data Types: char | string

References

[1] Cox, R. W., J. Ashburner, H. Breman, K. Fissell, C. Haselgrove, C.J. Holmes, J.L. Lancaster, D.E. Rex, S.M. Smith, J.B. Woodward, and S.C. Strother. 'A (sort of) new image data format standard: Nifti-1. " Neuroimage, Vol. 22(Suppl 1):e1440, 2004.

Introduced in R2017b

Was this topic helpful?