如何仅在MATLAB中的图像的一部分中添加噪声



我知道如何使用'imnoise'函数向图像添加噪声,但是我没有得到如何仅在图像的一部分中添加噪声补丁,而是留下其余的图像未触及。

您可以帮忙吗?

您可以在不分配加法变量的情况下添加噪声"原地",例如:

% 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);

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

相关内容

最新更新