| 26 | |
| 27 | |
| 28 | def random_crop(image, label): |
| 29 | border = 30 |
| 30 | image_width = image.size[0] |
| 31 | image_height = image.size[1] |
| 32 | border = int(min(image_width, image_height) * 0.1) |
| 33 | crop_win_width = np.random.randint(image_width - border, image_width) |
| 34 | crop_win_height = np.random.randint(image_height - border, image_height) |
| 35 | random_region = ( |
| 36 | (image_width - crop_win_width) >> 1, (image_height - crop_win_height) >> 1, (image_width + crop_win_width) >> 1, |
| 37 | (image_height + crop_win_height) >> 1) |
| 38 | return image.crop(random_region), label.crop(random_region) |
| 39 | |
| 40 | |
| 41 | def random_rotate(image, label, angle=15): |