def center_crop(img, dim):
    """
    Crops the input `img` from center to a specific dimention specified

    Args:
        img (numpy.ndarray): Image which needs to be cropped
        dim (tuple): Shape of the output image

    Returns:
        [numpy.ndarray]: Image croppepd to dim shape
    """

    width, height = img.shape[1], img.shape[0]

    # process crop width and height for max available dimension
    crop_width = dim[0] if dim[0] < img.shape[1] else img.shape[1]
    crop_height = dim[1] if dim[1] < img.shape[0] else img.shape[0]
    mid_x, mid_y = int(width / 2), int(height / 2)
    cw2, ch2 = int(crop_width / 2), int(crop_height / 2)
    crop_img = img[mid_y - ch2 : mid_y + ch2, mid_x - cw2 : mid_x + cw2]
    return crop_img