我正在尝试向图像添加随机噪声。当我尝试打印图像的形状时,它似乎可以正确打印,但是出现此错误,提示“'NoneType' 对象没有属性'shape'”
平台:Ubuntu 16.04;Python 版本:3.7.3;Opencv 版本:4.1.0
def rand_noise(image,prob):
print("Check",image.shape)
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
删除打印功能后,下一行显示相同的错误。
这是错误消息:
Check (720, 1280, 3)
Traceback (most recent call last):
File "noise&blur.py", line 71, in <module>
noise_imgR = sp_noise(imageR,0.005)
File "noise&blur.py", line 11, in sp_noise
print("Check",image.shape)
AttributeError: 'NoneType' object has no attribute 'shape'