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 http://nilearn.github.io/manipulating_images/input_output.html for a detailed description of the valid input types).

rtolfloat, optional

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

copybool, optional

Specifies whether cropped data is copied or not. Default=True.

padbool, optional

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

return_offsetbool, optional

Specifies whether to return a tuple of the removed padding. Default=False.

Returns
Niimg-like object orobj: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)]