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.iter_img¶
- nilearn.image.iter_img(imgs)[source]¶
Iterate over images.
Could be along the 4th dimension for 4D Niimg-like object or the 2nd dimension for 2D Surface images..
- Parameters:
- imgs4D Niimg-like object or
SurfaceImage
- imgs4D Niimg-like object or
- Returns:
- Iterator of
Nifti1ImageorSurfaceImage
- Iterator of
See also
Examples
>>> import numpy as np >>> from nibabel import Nifti1Image >>> from nilearn.image import iter_img >>> >>> # Create dummy 4D image. >>> affine = np.eye(4) >>> data = np.ones((3, 3, 3, 2)) >>> >>> # Set different values for each 3D image in 4D series. >>> for i in range(data.shape[-1]): ... data[:, :, :, i] = data[:, :, :, i] * i >>> >>> # Create 4D Nifti Image and print the shape of the data. >>> img_4d = Nifti1Image(data, affine) >>> f"{img_4d.__class__.__name__} with shape= {img_4d.shape}" 'Nifti1Image with shape= (3, 3, 3, 2)' >>> >>> # iter_img creates a generator object. >>> all_images = iter_img(img_4d) >>> type(all_images) <class 'generator'> >>> >>> # Let's check its content. >>> [f"{x.__class__.__name__} with shape= {x.shape}" for x in all_images] ['Nifti1Image with shape= (3, 3, 3)', 'Nifti1Image with shape= (3, 3, 3)']
Examples using nilearn.image.iter_img¶
Deriving spatial maps from group fMRI data using ICA and Dictionary Learning
Deriving spatial maps from group fMRI data using ICA and Dictionary Learning