def randomDistort2(img, num_steps=10, distort_limit=0.2, u=0.5):
if random.random() < u:
height, width, channel = img.shape
x_step = width // num_steps
xx = np.zeros(width, np.float32)
prev = 0
for x in range(0, width, x_step):
start = x
end = x + x_step
if end > width:
end = width
cur = width
else:
cur = prev + x_step * (1 + random.uniform(-distort_limit, distort_limit))
xx[start:end] = np.linspace(prev, cur, end - start)
prev = cur
y_step = height // num_steps
yy = np.zeros(height, np.float32)
prev = 0
for y in range(0, height, y_step):
start = y
end = y + y_step
if end > width:
end = height
cur = height
else:
cur = prev + y_step * (1 + random.uniform(-distort_limit, distort_limit))
yy[start:end] = np.linspace(prev, cur, end - start)
prev = cur
map_x, map_y = np.meshgrid(xx, yy)
map_x = map_x.astype(np.float32)
map_y = map_y.astype(np.float32)
img = cv2.remap(img, map_x, map_y, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101)
return img
## blur sharpen, etc
n06_pytorch_utils.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录