def _get_resize_size_and_scale( w, h, target_size, min_size=None, max_size=None, keep_aspect_ratio=True, resize_side="shorter", ): if keep_aspect_ratio: assert isinstance(target_size, int) aspect_ratio = float(min((w, h))) / float(max((w, h))) ( min_res_size, max_res_size, ) = image_test_util.compute_keep_aspect_ratio_resized_size( target_size, min_size, max_size, aspect_ratio, resize_side ) if w < h: res_w = min_res_size res_h = max_res_size else: res_w = max_res_size res_h = min_res_size else: assert isinstance(target_size, (list, tuple)) assert len(target_size) == 2 assert all(isinstance(size, int) for size in target_size) res_w, res_h = target_size scale_w = res_w / w scale_h = res_h / h return (res_w, res_h), (scale_w, scale_h)
def _get_target_resize_size(w, h, target_size, max_size): aspect_ratio = float(min((w, h))) / float(max((w, h))) ( min_res_size, max_res_size, ) = image_test_util.compute_keep_aspect_ratio_resized_size( target_size, None, max_size, aspect_ratio, "shorter") if w < h: res_w = min_res_size res_h = max_res_size else: res_w = max_res_size res_h = min_res_size scale_w = res_w / w scale_h = res_h / h return ((res_w, res_h), (scale_w, scale_h))