def randomFilter(img, limit=0.5, u=0.5):
if random.random() < u:
height, width, channel = img.shape
alpha = limit * random.uniform(0, 1)
##kernel = np.ones((5,5),np.float32)/25
kernel = np.ones((3, 3), np.float32) / 9 * 0.2
# type = random.randint(0,1)
# if type==0:
# kernel = np.ones((3,3),np.float32)/9*0.2
# if type==1:
# kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])*0.5
# kernel = alpha *sharp +(1-alpha)*blur
# kernel = np.random.randn(5, 5)
# kernel = kernel/np.sum(kernel*kernel)**0.5
img = alpha * cv2.filter2D(img, -1, kernel) + (1 - alpha) * img
img = np.clip(img, 0., 1.)
return img
##https://github.com/pytorch/vision/pull/27/commits/659c854c6971ecc5b94dca3f4459ef2b7e42fb70
## color augmentation
# brightness, contrast, saturation-------------
# from mxnet code, see: https://github.com/dmlc/mxnet/blob/master/python/mxnet/image.py
# def to_grayscle(img):
# blue = img[:,:,0]
# green = img[:,:,1]
# red = img[:,:,2]
# grey = 0.299*red + 0.587*green + 0.114*blue
# return grey
n06_pytorch_utils.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录