def get_bounded_shape(image, max_size):
    """get a shape with largest dimension <= max_size while preserving aspect ratio"""
    h, w, _ = image.shape
    aspect_ratio = w / h
    if h >= w:
        h = min(max_size, h)
        image_shape = (h, int(h * aspect_ratio))
    else:
        w = min(max_size, w)
        image_shape = (int(w / aspect_ratio), w)
    return image_shape