簡體   English   中英

如何在Matlab中僅向圖像的一部分添加噪點?

[英]How to add noise only to a part of the image in Matlab?

我知道如何使用“雜音”功能向圖像添加噪點,但是我沒有得到如何僅對圖像的一部分添加噪點補丁,而其余部分保持不變。

能否請你幫忙?

您可以“就地”添加噪聲,而無需分配附加變量,例如:

% 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圖像,則必須為每個通道重復該過程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM