Crop the image at random offset to get a patch of the given size. Args: patch(tuple): width and height of the patch inplace(Boolean): replace the internal images list with the patches if True; otherwise, return the patches.
(self, patch, inplace=True)
| 477 | return new_imgs |
| 478 | |
| 479 | def random_crop(self, patch, inplace=True): |
| 480 | '''Crop the image at random offset to get a patch of the given size. |
| 481 | |
| 482 | Args: |
| 483 | patch(tuple): width and height of the patch |
| 484 | inplace(Boolean): replace the internal images list with the patches |
| 485 | if True; otherwise, return the patches. |
| 486 | ''' |
| 487 | new_imgs = [] |
| 488 | for img in self.imgs: |
| 489 | assert img.size[0] >= patch[0] and img.size[1] >= patch[1],\ |
| 490 | 'img size (%d, %d), patch size (%d, %d)' % \ |
| 491 | (img.size[0], img.size[1], patch[0], patch[1]) |
| 492 | left_offset = random.randint(0, img.size[0] - patch[0]) |
| 493 | top_offset = random.randint(0, img.size[1] - patch[1]) |
| 494 | box = (left_offset, top_offset, left_offset + patch[0], |
| 495 | top_offset + patch[1]) |
| 496 | new_imgs.append(img.crop(box)) |
| 497 | |
| 498 | if inplace: |
| 499 | self.imgs = new_imgs |
| 500 | return self |
| 501 | else: |
| 502 | return new_imgs |
| 503 | |
| 504 | def random_crop_resize(self, patch, inplace=True): |
| 505 | ''' Crop of the image at a random size between 0.08 to 1 of input image |
no test coverage detected