我正在尝试使用以下代码向某些图像添加高斯噪声
ExecutorService
但是它不起作用,它给我以下错误
noisy_image [:,:,0] = img [:,:,0] +高斯ValueError:操作数 无法与形状一起广播(315,500)(224,224)
请仔细检查并提供反馈。
答案 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
添加到每个频道。