| 80 | self.size = size |
| 81 | |
| 82 | def __call__(self, img, mask): |
| 83 | assert img.size == mask.size |
| 84 | w, h = img.size |
| 85 | if (w >= h and w == self.size) or (h >= w and h == self.size): |
| 86 | return img, mask |
| 87 | if w > h: |
| 88 | ow = self.size |
| 89 | oh = int(self.size * h / w) |
| 90 | return img.resize((ow, oh), Image.BILINEAR), mask.resize((ow, oh), Image.NEAREST) |
| 91 | else: |
| 92 | oh = self.size |
| 93 | ow = int(self.size * w / h) |
| 94 | return img.resize((ow, oh), Image.BILINEAR), mask.resize((ow, oh), Image.NEAREST) |
| 95 | |
| 96 | |
| 97 | class RandomSizedCrop(object): |