MCPcopy Create free account
hub / github.com/IceClear/StableSR / random_crop

Function random_crop

scripts/util_image.py:587–600  ·  view source on GitHub ↗

Randomly crop a patch from the give image.

(im, pch_size)

Source from the content-addressed store, hash-verified

585
586# ----------------------Patch Cropping----------------------------
587def 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
602class RandomCrop:
603 def __init__(self, pch_size):

Callers 1

__call__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected