Randomly crop a patch from the give image.
(im, pch_size)
| 585 | |
| 586 | # ----------------------Patch Cropping---------------------------- |
| 587 | def random_crop(im, pch_size): |
| 588 | ''' |
| 589 | Randomly crop a patch from the give image. |
| 590 | ''' |
| 591 | h, w = im.shape[:2] |
| 592 | if h == pch_size and w == pch_size: |
| 593 | im_pch = im |
| 594 | else: |
| 595 | assert h >= pch_size or w >= pch_size |
| 596 | ind_h = random.randint(0, h-pch_size) |
| 597 | ind_w = random.randint(0, w-pch_size) |
| 598 | im_pch = im[ind_h:ind_h+pch_size, ind_w:ind_w+pch_size,] |
| 599 | |
| 600 | return im_pch |
| 601 | |
| 602 | class RandomCrop: |
| 603 | def __init__(self, pch_size): |