如何在Matlab中仅向图像的一部分添加噪点?

时间:2019-03-11 00:32:03

标签: matlab

我知道如何使用'imnoise'功能向图像添加噪点,但是我没有得到如何仅对图像的一部分添加噪点补丁,而其余图像则保持不变。

能请你帮忙吗?

2 个答案:

答案 0 :(得分:1)

您可以“就地”添加噪声,而无需分配附加变量,例如:

% Test image.
img = uint8(repmat([zeros(20), 255*ones(20); 255*ones(20) zeros(20)], 5, 5));

% Show test image before noise.
figure(1);
imshow(img);

% Add noise only to part of image.
img(20:60, 20:80) = imnoise(img(20:60, 20:80), 'gaussian');

% Show test image after noise.
figure(2);
imshow(img);

答案 1 :(得分:0)

最简单的方法可能是拍摄原始图像的一个区域(例如,region = img(4:40,50:60)给该图像添加噪声(将其称为region_with_noise),然后将其拼接回(img(4 :40,50:60)= region_with_noise)。如果您有RGB图像,则必须为每个通道重复该过程。