def _translate(image, horizontal=(0,40), vertical=(0,10)):
'''
Randomly translate the input image horizontally and vertically.
Arguments:
image (array-like): The image to be translated.
horizontal (int tuple, optinal): A 2-tuple `(min, max)` with the minimum
and maximum horizontal translation. A random translation value will
be picked from a uniform distribution over [min, max].
vertical (int tuple, optional): Analog to `horizontal`.
Returns:
The translated image and the horzontal and vertical shift values.
'''
rows,cols,ch = image.shape
x = np.random.randint(horizontal[0], horizontal[1]+1)
y = np.random.randint(vertical[0], vertical[1]+1)
x_shift = random.choice([-x, x])
y_shift = random.choice([-y, y])
M = np.float32([[1,0,x_shift],[0,1,y_shift]])
return cv2.warpAffine(image, M, (cols, rows)), x_shift, y_shift
评论列表
文章目录