多任务学习目标识别和语义分割数据增广,批处理对图像添加校验椒盐和高斯噪声,同时xml,label不做更改,重新编号写入文件夹
"添加椒盐噪声"
def sp_noise(image,prob): # prob:噪声比例
output = np.zeros(image.shape,np.uint8)
thres = 1 - prob
for i in range(image.shape[0]):
for j in range(image.shape[1]):
rdn = random.random()
if rdn < prob:
output[i][j] = 0
elif rdn > thres:
output[i][j] = 255
else:
output[i][j] = image[i][j]
return output
"添加高斯噪声"
def gasuss_noise(image, mean=0, var=0.001): # mean : 均值 var : 方差
image = np.array(image/255, dtype=float)
noise = np.random.normal(mean, var ** 0.5, image.shape)
out = image + noise
if out.min() < 0:
low_clip = -1.
else:
low_clip = 0.
out = np.clip(out, low_clip, 1.0)
out = np.u