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.new_img_like

nilearn.image.new_img_like(ref_niimg, data, affine=None, copy_header=False)[source]

Create a new image of the same class as the reference image.

Parameters:
ref_niimgNiimg-like object or SurfaceImage

Reference image. The new image will be of the same type.

datanumpy.ndarray, PolyData, or dict of numpy.ndarray, str, pathlib.Path

Data to be stored in the image. If data dtype is a boolean, then data is cast to ‘uint8’ by default.

Changed in version 0.9.2: Changed default dtype casting of booleans from ‘int8’ to ‘uint8’.

If ref_niimg is a Niimg-like object, then data must be a numpy.ndarray.

affine4x4 numpy.ndarray, default=None

Transformation matrix. Ignored for SurfaceImage.

copy_headerbool, default=False

Indicated if the header of the reference image should be used to create the new image. Ignored for SurfaceImage.

Returns:
Niimg-like or SurfaceImage object

A loaded image with the same file type (and, optionally, header) as the reference image.

Examples using nilearn.image.new_img_like

Visualizing global patterns with a carpet plot

Visualizing global patterns with a carpet plot

Searchlight analysis of face vs house recognition

Searchlight analysis of face vs house recognition

Comparing connectomes on different reference atlases

Comparing connectomes on different reference atlases

Computing a Region of Interest (ROI) mask manually

Computing a Region of Interest (ROI) mask manually

Copying headers from input images with math_img

Copying headers from input images with math_img

NeuroVault meta-analysis of stop-go paradigm studies

NeuroVault meta-analysis of stop-go paradigm studies

Working with long time series fMRI images

Working with long time series fMRI images