| 11 | |
| 12 | |
| 13 | class GroupRandomCrop(object): |
| 14 | def __init__(self, size): |
| 15 | if isinstance(size, numbers.Number): |
| 16 | self.size = (int(size), int(size)) |
| 17 | else: |
| 18 | self.size = size |
| 19 | |
| 20 | def __call__(self, img_group): |
| 21 | |
| 22 | w, h = img_group[0].size |
| 23 | th, tw = self.size |
| 24 | |
| 25 | out_images = list() |
| 26 | |
| 27 | x1 = random.randint(0, w - tw) |
| 28 | y1 = random.randint(0, h - th) |
| 29 | |
| 30 | for img in img_group: |
| 31 | assert(img.size[0] == w and img.size[1] == h) |
| 32 | if w == tw and h == th: |
| 33 | out_images.append(img) |
| 34 | else: |
| 35 | out_images.append(img.crop((x1, y1, x1 + tw, y1 + th))) |
| 36 | |
| 37 | return out_images |
| 38 | |
| 39 | |
| 40 | class GroupCenterCrop(object): |
no outgoing calls
no test coverage detected