imagelib: random crop func (unused)

This commit is contained in:
iperov 2021-04-15 21:43:18 +04:00
parent bee8628d77
commit 65432d0c3d
2 changed files with 12 additions and 1 deletions

View file

@ -1,5 +1,16 @@
import numpy as np
def random_crop(img, w, h):
height, width = img.shape[:2]
h_rnd = height - h
w_rnd = width - w
y = np.random.randint(0, h_rnd) if h_rnd > 0 else 0
x = np.random.randint(0, w_rnd) if w_rnd > 0 else 0
return img[y:y+height, x:x+width]
def normalize_channels(img, target_channels):
img_shape_len = len(img.shape)
if img_shape_len == 2: