MCPcopy
hub / github.com/fudan-generative-vision/champ / crop_bbox

Function crop_bbox

datasets/data_utils.py:44–56  ·  view source on GitHub ↗
(img, bbox, do_resize=False, size=512)

Source from the content-addressed store, hash-verified

42 return scaled_xmin, scaled_ymin, scaled_xmax, scaled_ymax
43
44def crop_bbox(img, bbox, do_resize=False, size=512):
45
46 if isinstance(img, (Path, str)):
47 img = Image.open(img)
48 cropped_img = img.crop(bbox)
49 if do_resize:
50 cropped_W, cropped_H = cropped_img.size
51 ratio = size / max(cropped_W, cropped_H)
52 new_W = cropped_W * ratio
53 new_H = cropped_H * ratio
54 cropped_img = cropped_img.resize((new_W, new_H))
55
56 return cropped_img
57
58def mask_to_bbox(mask_path):
59 mask = np.array(Image.open(mask_path))[..., 0]

Callers 2

__getitem__Method · 0.90
__getitem__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected