def center_crop(img, crop_height, crop_width):
    """ Crop the central part of an image.

    Args:
        img (ndarray): image to be cropped.
        crop_height (int): height of the crop.
        crop_width (int): width of the crop.

    Return:
        (ndarray): the cropped image.
    """
    def get_center_crop_coords(height, width, crop_height, crop_width):
        y1 = (height - crop_height) // 2
        y2 = y1 + crop_height
        x1 = (width - crop_width) // 2
        x2 = x1 + crop_width
        return x1, y1, x2, y2

    height, width = img.shape[:2]
    x1, y1, x2, y2 = get_center_crop_coords(
        height, width, crop_height, crop_width)
    return img[y1:y2, x1:x2, ...]