def crop(img, min_h, min_w):
    """
    Crop image to smallest height or width.
    The `None` value will be kept to the image's dim size,
    the other dimension one will be center-cropped to the
    non-`None` value.

    Args:
        img (np.array): image
        min_h (int): height
        min_w (int): width

    Returns:
        np.array: cropped image
    """
    if min_w is None:
        im_h = img.shape[0]
        center = im_h // 2
        start_h = max([0, center - min_h // 2])
        end_h = min([im_h, center + min_h // 2])

        return img[start_h:end_h, :]

    im_w = img.shape[1]
    center = im_w // 2
    start_w = max([0, center - min_w // 2])
    end_w = min([im_w, center + min_w // 2])

    return img[:, start_w:end_w]