def randomShiftScale(img, u=0.25, limit=4):
if random.random() < u:
height, width, channel = img.shape
assert (width == height)
size0 = width
size1 = width + 2 * limit
img1 = cv2.copyMakeBorder(img, limit, limit, limit, limit, borderType=cv2.BORDER_REFLECT_101)
size = round(random.uniform(size0, size1))
dx = round(random.uniform(0, size1 - size)) # pixel
dy = round(random.uniform(0, size1 - size))
y1 = dy
y2 = y1 + size
x1 = dx
x2 = x1 + size
if size == size0:
img = img1[y1:y2, x1:x2, :]
else:
img = cv2.resize(img1[y1:y2, x1:x2, :], (size0, size0), interpolation=cv2.INTER_LINEAR)
return img
n06_pytorch_utils.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录