我正在尝试向图像添加随机噪声。当我尝试打印图像的形状时,它似乎可以正确打印,但是会出现此错误,提示“'NoneType'对象没有属性'形状'”
平台: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'