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.crop_img#

nilearn.image.crop_img(img, rtol=1e-08, copy=True, pad=True, return_offset=False)[source]#

Crops an image as much as possible.

Will crop img, removing as many zero entries as possible without touching non-zero entries. Will leave one voxel of zero padding around the obtained non-zero area in order to avoid sampling issues later on.

Parameters:
imgNiimg-like object

Image to be cropped (see Input and output: neuroimaging data representation for a detailed description of the valid input types).

rtolfloat, default=1e-8

relative tolerance (with respect to maximal absolute value of the image), under which values are considered negligeable and thus croppable.

copybool, default=True

Specifies whether cropped data is copied or not.

padbool, default=True

Toggles adding 1-voxel of 0s around the border.

return_offsetbool, default=False

Specifies whether to return a tuple of the removed padding.

Returns:
Niimg-like object or tuple

Cropped version of the input image and, if return_offset=True, a tuple of tuples representing the number of voxels removed (before, after) the cropped volumes, i.e.: [(x1_pre, x1_post), (x2_pre, x2_post), …, (xN_pre, xN_post)]