给图像增加高斯噪声

时间:2019-03-20 12:44:20

标签: python numpy opencv

我正在尝试使用以下代码向某些图像添加高斯噪声

ExecutorService

但是它不起作用,它给我以下错误

  

noisy_image [:,:,0] = img [:,:,0] +高斯ValueError:操作数   无法与形状一起广播(315,500)(224,224)

请仔细检查并提供反馈。

1 个答案:

答案 0 :(得分:4)

看起来您的图像形状为(315,500),而gaussian的形状为(224,224)。尝试将高斯初始化更改为

gaussian = np.random.normal(mean, sigma, (img.shape[0],img.shape[1])) 

顺便说一句: 您可以替换这些行

noisy_image[:, :, 0] = img[:, :, 0] + gaussian
noisy_image[:, :, 1] = img[:, :, 1] + gaussian
noisy_image[:, :, 2] = img[:, :, 2] + gaussian

使用

noisy_image = img + gaussian

具有相同的效果:将gaussian添加到每个频道。

相关问题