def resize_max(img, max_side):
    """
    Resize the image to threshold the maximum dimension within max_side
    :param img:
    :param max_side: Length of the maximum height or width
    :return:
    """
    h, w = img.shape[:2]
    if h > w:
        nh = max_side
        nw = w * (nh / h)
    else:
        nw = max_side
        nh = h * (nw / w)

    return cv.resize(img, (nw, nh))