(img, bbox, do_resize=False, size=512)
| 42 | return scaled_xmin, scaled_ymin, scaled_xmax, scaled_ymax |
| 43 | |
| 44 | def 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 | |
| 58 | def mask_to_bbox(mask_path): |
| 59 | mask = np.array(Image.open(mask_path))[..., 0] |
no outgoing calls
no test coverage detected