| 44 | |
| 45 | |
| 46 | class CenterCrop(object): |
| 47 | def __init__(self, size): |
| 48 | if isinstance(size, numbers.Number): |
| 49 | self.size = (int(size), int(size)) |
| 50 | else: |
| 51 | self.size = size |
| 52 | |
| 53 | def __call__(self, img, mask): |
| 54 | assert img.size == mask.size |
| 55 | w, h = img.size |
| 56 | th, tw = self.size |
| 57 | x1 = int(round((w - tw) / 2.)) |
| 58 | y1 = int(round((h - th) / 2.)) |
| 59 | return img.crop((x1, y1, x1 + tw, y1 + th)), mask.crop((x1, y1, x1 + tw, y1 + th)) |
| 60 | |
| 61 | |
| 62 | class RandomHorizontallyFlip(object): |