MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / resize

Function resize

detrsmpl/data/datasets/pipelines/transforms.py:543–575  ·  view source on GitHub ↗
(ori_shape, size, max_size=None)

Source from the content-addressed store, hash-verified

541
542
543def resize(ori_shape, size, max_size=None):
544 # size can be min_size (scalar) or (w, h) tuple
545 # import ipdb; ipdb.set_trace(context=15)
546 def get_size_with_aspect_ratio(image_size, size, max_size=None):
547 w, h = image_size
548 if max_size is not None:
549 min_original_size = float(min((w, h)))
550 max_original_size = float(max((w, h)))
551 if max_original_size / min_original_size * size > max_size:
552 size = int(
553 round(max_size * min_original_size / max_original_size))
554
555 if (w <= h and w == size) or (h <= w and h == size):
556 return (w, h)
557
558 if w < h:
559 ow = size
560 oh = int(size * h / w)
561 else:
562 oh = size
563 ow = int(size * w / h)
564
565 return (ow, oh)
566
567 def get_size(ori_shape, size, max_size=None):
568 if isinstance(size, (list, tuple)):
569 return size[::-1]
570 else:
571 return get_size_with_aspect_ratio(ori_shape, size, max_size)
572
573 size = get_size(ori_shape, size, max_size)
574
575 return size
576
577
578@PIPELINES.register_module()

Callers 1

__call__Method · 0.70

Calls 1

get_sizeFunction · 0.70

Tested by

no test coverage detected