Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.

nilearn.image.check_niimg

nilearn.image.check_niimg(niimg, ensure_ndim=None, atleast_4d=False, dtype=None, return_iterator=False, wildcards=True)[source]

Check that niimg is a proper 3D/4D niimg.

Turn filenames into objects.

Parameters:
niimgNiimg-like object

See Input and output: neuroimaging data representation. If niimg is a string or pathlib.Path, consider it as a path to Nifti image and call nibabel.load on it. The '~' symbol is expanded to the user home folder. If it is an object, check if the affine attribute present and that nilearn.image.get_data returns a result, raise TypeError otherwise.

ensure_ndim{3, 4, None}, default=None

Indicate the dimensionality of the expected niimg. An error is raised if the niimg is of another dimensionality.

atleast_4dbool, default=False

Indicates if a 3d image should be turned into a single-scan 4d niimg.

dtypedtype like, “auto” or None, default=None

Data type toward which the data should be converted. If “auto”, the data will be converted to int32 if dtype is discrete and float32 if it is continuous. If None, data will not be converted to a new data type.

return_iteratorbool, default=False

Returns an iterator on the content of the niimg file input.

wildcardsbool, default=True

Use niimg as a regular expression to get a list of matching input filenames. If multiple files match, the returned list is sorted using an ascending order. If no file matches the regular expression, a ValueError exception is raised.

Returns:
result3D/4D Niimg-like object

Result can be nibabel.Nifti1Image or the input, as-is. It is guaranteed that the returned object has an affine attribute and that its data can be retrieved with nilearn.image.get_data.

Notes

In nilearn, special care has been taken to make image manipulation easy. This method is a kind of pre-requisite for any data processing method in Nilearn because it checks if data have a correct format and loads them if necessary.

Its application is idempotent.