根据盐和胡椒的概率,如何将椒盐噪声分别添加到图像中。 imnoise
作为一个整体的噪声密度将取一个值,该值是盐(白点)和胡椒(黑点)的测量值。我想知道如果我们只是分别用两种不同的概率添加白色(盐)和黑色(胡椒)噪音。必须使用什么等式?手动添加图像中的脉冲噪声
回答
clc;
close all;
originalImage = imread('Cameraman.tif');
[rows cols] = size(originalImage);
totalPixels = int32(rows * cols);
subplot(1, 2, 1);
imshow(originalImage);
percentage = str2double(cell2mat(inputdlg('Enter the percent noise: ', 'Enter answer', 1, {'2'})))/100.;
numberOfNoisePixels = int32(percentage * double(rows) * double(cols));
locations = randi(totalPixels, [numberOfNoisePixels, 1]);
noisyImage = originalImage;
noisyImage(locations) = 255;
subplot(1, 2, 2);
imshow(noisyImage, []);
来源
https://groups.google.com/forum/#!topic/comp.soft-sys.matlab/YcF2xZwnq1o
那请问盐噪声,椒盐噪声会
noisyImage(locations) = 0;
,而不是
noisyImage(locations) = 255;
img = .5*ones(100,200); %// example image
p_salt = .05; %// probability of salt
p_pepper = .01; %// probability of pepper
if strcmp(class(img),'uint8')
salt_value = uint8(255);
else
salt_value = 1;
end
pepper_value = 0;
aux = rand(size(img)); %// generate random values
img(aux<=p_salt) = salt_value; %// add salt
img((aux>p_salt) & (aux<=p_salt+p_pepper)) = pepper_value; %// add pepper
imshow(img) %// show image
该方法与imnoise
中使用的方法相似,避免了在相同像素处添加盐和胡椒粉。它假定p_salt + p_pepper
至多1
根据强度会对此代码有任何影响值在0-255或0-1之间? – learner
@LandonAshes更正。感谢您指出 –
此代码是简单而有用的(在MATLAB同imnoise)
im=imread('Parrot.jpg');
B=rgb2gray(im);
%if Pa==Pb;
percen=10;
%Noise level 10
Prob_den_f=255*percen/100;
NoiseImg = B;
Rmatrix = randint(size(B,1),size(B,2),[0,255]);
NoiseImg(Rmatrix <=Prob_den_f/2) = 0;
NoiseImg(Rmatrix >Prob_den_f/2&Rmatrix<Prob_den_f) =255;
subplot(1,2,2),imshow(NoiseImg),title('Add ''Salt and Pepper'' Noise');
subplot(1,2,1),imshow(B),title('Original Image');
请添加说明,而不是仅发布代码。 –
- 1. 向图像添加噪声
- 2. 如何在matlab中不使用imnoise函数的情况下将脉冲和gamma噪声添加到图像中?
- 3. 将泊松噪声添加到图像
- 4. 将RMS噪声添加到图像
- 5. CSS动画脉冲部分的图像
- 6. 创建噪声图像(随机噪声)
- 7. Image双精度图像中的泊松噪声(散粒噪声)
- 8. 如何脉冲图像并改变脉冲率?
- 9. jquery滑动手柄应脉冲颜色
- 10. 脉冲动画
- 11. 从图像中去除胡椒噪声和盐噪声
- 12. 图像噪声过滤
- 13. 阈值图像和噪声
- 14. 噪声图像压缩
- 15. d3中的脉冲图
- 16. 如何添加文字在图像的顶部像在Android的脉冲
- 17. 试图用噪音,numpy和图像创建噪声图像
- 18. 噪声图像中的特征检测
- 19. 图像中的“混合”噪声?
- 20. UIBezierPath脉冲动画
- 21. 动画脉冲UILabel?
- 22. 如何添加泊松噪声和高斯噪声?
- 23. 鉴于噪声分布情况,噪声破坏图像?
- 24. 在C中生成白噪声图像#
- 25. 如何为图像添加噪点?
- 26. 如何减少图像中的冲动噪音?
- 27. iPhone上的脉冲动画
- 28. Google地图标记脉冲动画?
- 29. jQuery手机:动态添加图像
- 30. 向Silverlight控件动态添加脉冲边界
只是一个问题,我打正确的前)。噪音的百分比和噪音的“概率”。在图像处理中这两个相同的术语? – learner
不完全,但足够接近。 %是一个固定的项,所以0.05%将意味着始终有0.05 *总像素。概率将会接近0.05 *总像素。随着像素增加,这两个术语将开始意味着相同的东西 – exussum
这种方法不会阻止在相同的像素处添加盐和噪声(可能需要或不需要) –