Image Cropping

hugheslab.im_tools.crop_image(img, centre, dims)

Crops an image or stack of images stored as a numpy array, with cropping performed around a specified central point.

Arguments:
img: ndarray

2D or 3D image as numpy array. If 2D must be (y,x), if 3D, must be (frame_number, y, x)

centre: tuple of (int, int)

pixel to be at centre of cropped image (x, y)

dims: tuple of (int, int)

size of cropped image (width, height)

Returns:

ndarray: cropped image or stack of cropped images

hugheslab.im_tools.crop_zero(img)

Crops an image to the smallest rectangle that contains all non-zero pixels.

Returns cropped image as 2D numpy array.

Arguments:
imgndarray

image as numpy array

Returns

ndarray, cropped image

hugheslab.im_tools.extract_central(img, boxSize=None)

Extract a central square from an image. The extracted square is centred on the input image, with size 2 * boxSize if possible, otherwise the largest square that can be extracted.

Returns cropped image as 2D numpy array.

Arguments:

img : input image as 2D numpy array

Keyword Arguments:

boxSize : size of cropping square, default is largest possible

Returns:

ndarray, cropped image