Neuroimaging in Python — NiBabel 5.4.0.dev1+g3b1c7b37 documentation (original) (raw)
nifti2
¶
Read / write access to NIfTI2 image format
Format described here:
Nifti2Header([binaryblock, endianness, ...]) | Class for NIfTI2 header |
---|---|
Nifti2Image(dataobj, affine[, header, ...]) | Class for single file NIfTI2 format image |
Nifti2Pair(dataobj, affine[, header, extra, ...]) | Class for NIfTI2 format image, header pair |
Nifti2PairHeader([binaryblock, endianness, ...]) | Class for NIfTI2 pair header |
load(filename) | Load NIfTI2 single or pair image from filename |
save(img, filename) | Save NIfTI2 single or pair to filename |
Nifti2Image¶
class nibabel.nifti2.Nifti2Image(dataobj, affine, header=None, extra=None, file_map=None, dtype=None)¶
Bases: Nifti1Image
Class for single file NIfTI2 format image
Initialize image
The image is a combination of (array-like, affine matrix, header), with optional metadata in extra, and filename / file-like objects contained in the file_map mapping.
Parameters:
dataobjobject
Object containing image data. It should be some object that returns an array from np.asanyarray
. It should have a shape
attribute or property
affineNone or (4,4) array-like
homogeneous affine giving relationship between voxel coordinates and world coordinates. Affine can also be None. In this case,obj.affine
also returns None, and the affine as written to disk will depend on the file format.
headerNone or mapping or header instance, optional
metadata for this image format
extraNone or mapping, optional
metadata to associate with image that cannot be stored in the metadata of this image type
file_mapmapping, optional
mapping giving file information for this image format
Notes
If both a header and an affine are specified, and the affine does not match the affine that is in the header, the affine will be used, but the sform_code
and qform_code
fields in the header will be re-initialised to their default values. This is performed on the basis that, if you are changing the affine, you are likely to be changing the space to which the affine is pointing. The set_sform()
andset_qform()
methods can be used to update the codes after an image has been created - see those methods, and the manual for more details.
__init__(dataobj, affine, header=None, extra=None, file_map=None, dtype=None)¶
Initialize image
The image is a combination of (array-like, affine matrix, header), with optional metadata in extra, and filename / file-like objects contained in the file_map mapping.
Parameters:
dataobjobject
Object containing image data. It should be some object that returns an array from np.asanyarray
. It should have a shape
attribute or property
affineNone or (4,4) array-like
homogeneous affine giving relationship between voxel coordinates and world coordinates. Affine can also be None. In this case,obj.affine
also returns None, and the affine as written to disk will depend on the file format.
headerNone or mapping or header instance, optional
metadata for this image format
extraNone or mapping, optional
metadata to associate with image that cannot be stored in the metadata of this image type
file_mapmapping, optional
mapping giving file information for this image format
Notes
If both a header and an affine are specified, and the affine does not match the affine that is in the header, the affine will be used, but the sform_code
and qform_code
fields in the header will be re-initialised to their default values. This is performed on the basis that, if you are changing the affine, you are likely to be changing the space to which the affine is pointing. The set_sform()
andset_qform()
methods can be used to update the codes after an image has been created - see those methods, and the manual for more details.
alias of Nifti2Header
Nifti2Pair¶
class nibabel.nifti2.Nifti2Pair(dataobj, affine, header=None, extra=None, file_map=None, dtype=None)¶
Bases: Nifti1Pair
Class for NIfTI2 format image, header pair
Initialize image
The image is a combination of (array-like, affine matrix, header), with optional metadata in extra, and filename / file-like objects contained in the file_map mapping.
Parameters:
dataobjobject
Object containing image data. It should be some object that returns an array from np.asanyarray
. It should have a shape
attribute or property
affineNone or (4,4) array-like
homogeneous affine giving relationship between voxel coordinates and world coordinates. Affine can also be None. In this case,obj.affine
also returns None, and the affine as written to disk will depend on the file format.
headerNone or mapping or header instance, optional
metadata for this image format
extraNone or mapping, optional
metadata to associate with image that cannot be stored in the metadata of this image type
file_mapmapping, optional
mapping giving file information for this image format
Notes
If both a header and an affine are specified, and the affine does not match the affine that is in the header, the affine will be used, but the sform_code
and qform_code
fields in the header will be re-initialised to their default values. This is performed on the basis that, if you are changing the affine, you are likely to be changing the space to which the affine is pointing. The set_sform()
andset_qform()
methods can be used to update the codes after an image has been created - see those methods, and the manual for more details.
__init__(dataobj, affine, header=None, extra=None, file_map=None, dtype=None)¶
Initialize image
The image is a combination of (array-like, affine matrix, header), with optional metadata in extra, and filename / file-like objects contained in the file_map mapping.
Parameters:
dataobjobject
Object containing image data. It should be some object that returns an array from np.asanyarray
. It should have a shape
attribute or property
affineNone or (4,4) array-like
homogeneous affine giving relationship between voxel coordinates and world coordinates. Affine can also be None. In this case,obj.affine
also returns None, and the affine as written to disk will depend on the file format.
headerNone or mapping or header instance, optional
metadata for this image format
extraNone or mapping, optional
metadata to associate with image that cannot be stored in the metadata of this image type
file_mapmapping, optional
mapping giving file information for this image format
Notes
If both a header and an affine are specified, and the affine does not match the affine that is in the header, the affine will be used, but the sform_code
and qform_code
fields in the header will be re-initialised to their default values. This is performed on the basis that, if you are changing the affine, you are likely to be changing the space to which the affine is pointing. The set_sform()
andset_qform()
methods can be used to update the codes after an image has been created - see those methods, and the manual for more details.
alias of Nifti2PairHeader
load¶
nibabel.nifti2.load(filename)¶
Load NIfTI2 single or pair image from filename
Parameters:
filenamestr
filename of image to be loaded
Returns:
imgNifti2Image or Nifti2Pair
nifti2 single or pair image instance
Raises:
ImageFileError
if filename doesn’t look like nifti2;
OSError
if filename does not exist.
save¶
nibabel.nifti2.save(img, filename)¶
Save NIfTI2 single or pair to filename
Parameters:
filenamestr
filename to which to save image