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.
8.5.5. nilearn.image.crop_img¶
nilearn.image.
crop_img
(img, rtol=1e-08, copy=True, pad=True, return_offset=False)¶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: img : Niimg-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).
rtol :
float
relative tolerance (with respect to maximal absolute value of the image), under which values are considered negligeable and thus croppable.
copy :
bool
Specifies whether cropped data is copied or not (default is True).
pad :
bool
Toggles adding 1-voxel of 0s around the border (default is True).
return_offset :
bool
Specifies whether to return a tuple of the removed padding (default is False).
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)]