資源簡介
matlab 噪聲與濾波去噪的源代碼 還有不同噪聲和濾波的對比分析文檔
代碼片段和文件信息
M?=?imread(‘a.jpg‘);???????????
gray?=?rgb2gray(M);
figure;
subplot(321)imshow(M);????????????????%顯示原始圖像
title(‘原圖‘);
subplot(322)imshow(gray);?????????????????????????%顯示灰度圖像
title(‘灰度圖‘);
P1?=?imnoise(gray‘gaussian‘0.02);?????%加入高斯躁聲?
P2?=?imnoise(gray‘salt?&?pepper‘0.02);?%加入椒鹽躁聲
subplot(323)imshow(P1);????????????????????????%加入高斯躁聲后顯示圖像
title(‘高斯噪聲(方差為0.02)‘);
subplot(324)imshow(P2);????????????????????????%加入椒鹽躁聲后顯示圖像??
title(‘椒鹽噪聲(方差為0.02)‘);
P3?=?imnoise(gray‘gaussian‘0.1);?????%加入高斯躁聲?
P4?=?imnoise(gray‘salt?&?pepper‘0.1);?%加入椒鹽躁聲
subplot(325)imshow(P3);????????????????????????%加入高斯躁聲后顯示圖像
title(‘高斯噪聲(方差為0.1)‘);
subplot(326)imshow(P4);????????????????????????%加入椒鹽躁聲后顯示圖像??
title(‘椒鹽噪聲(方差為0.1)‘);
%對高斯噪聲高斯加權3
n?=?3;
template?=?ones(n);
[height?width]?=?size(P1);
x1?=?double(P1);
x2?=?x1;
for?i?=?1:height-n+1
????for?j?=?1:width-n+1
????????c?=?x1(i:i+n-1j:j+n-1).*template;
????????s?=?sum(sum(c));
????????x2(i+(n-1)/2j+(n-1)/2)?=?s/(n*n);
????end
end
g?=?uint8(x2);
figure;
subplot(221)imshow(g);
title(‘高斯噪聲高斯加權濾波(3*3)‘);
%對高斯噪聲高斯加權5
n?=?5;
template?=?ones(n);
[height?width]?=?size(P1);
x1?=?double(P1);
x2?=?x1;
for?i?=?1:height-n+1
????for?j?=?1:width-n+1
????????c?=?x1(i:i+n-1j:j+n-1).*template;
????????s?=?sum(sum(c));
????????x2(i+(n-1)/2j+(n-1)/2)?=?s/(n*n);
????end
end
g?=?uint8(x2);
subplot(222)imshow(g);
title(‘高斯噪聲高斯加權濾波(5*5)‘);
%對椒鹽噪聲高斯加權3
n?=?3;
template?=?ones(n);
[height?width]?=?size(P2);
x1?=?double(P2);
x2?=?x1;
for?i?=?1:height-n+1
????for?j?=?1:width-n+1
????????c?=?x1(i:i+n-1j:j+n-1).*template;
????????s?=?sum(sum(c));
????????x2(i+(n-1)/2j+(n-1)/2)?=?s/(n*n);
????end
end
g?=?uint8(x2);
subplot(223)imshow(g);
title(‘椒鹽噪聲高斯加權濾波(3*3)‘);
%對椒鹽噪聲高斯加權5
n?=?5;
template?=?ones(n);
[height?width]?=?size(P2);
x1?=?double(P2);
x2?=?x1;
for?i?=?1:height-n+1
????for?j?=?1:width-n+1
????????c?=?x1(i:i+n-1j:j+n-1).*template;
????????s?=?sum(sum(c));
????????x2(i+(n-1)/2j+(n-1)/2)?=?s/(n*n);
????end
end
g?=?uint8(x2);
subplot(224)imshow(g);
title(‘椒鹽噪聲高斯加權濾波(5*5)‘);
%對高斯躁聲中值濾波3
n=3;
[height?width]?=?size(P1);
x1?=?double(P1);
x2?=?x1;
for?i?=?1:height-n+1
????for?j?=?1:width-n+1
????????c?=?x1(i:i+n-1j:j+n-1);
????????e?=?c(1:);
????????for?f?=?2:n
????????????e?=?[e?c(f?:)];
????????end
????????tmp?=?median(e);
????????x2(i+(n-1)/2j+(n-1)/2)?=?tmp;
????end
end
a?=?uint8(x2);
figure;
subplot(221)imshow(a);
title(‘高斯噪聲中值濾波(3*3)‘);
%對高斯躁聲中值濾波5
n=5;
[height?width]?=?size(P1);
x1?=?double(P1);
x2?=?x1;
for?i?=?1:height-n+1
????for?j?=?1:width-n+1
????????c?=?x1(i:i+n-1j:j+n-1);
????????e?=?c(1:);
????????for?f?=?2:n
????????????e?=?[e?c(f?:)];
????????end
????????tmp?=?median(e);
????????x2(i+(n-1)/2j+(n-1)/2)?=?tmp;
????end
end
a?=?uint8(x2);
subplot(222)imshow(a);
title(‘高斯噪聲中值濾波(5*5)‘);
%對椒鹽躁聲中值濾波3
n=3;
[height?width]?=?size(P2);
y1
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????160345??2018-09-26?22:02??a.jpg
?????文件???????4716??2018-09-29?17:49??Unti
?????文件???14467055??2018-09-29?18:06??噪聲與去噪對比分析.docx
-----------?---------??----------?-----??----
?????????????14632116????????????????????3
- 上一篇:EWT 經驗小波變換matlab源程序
- 下一篇:監督分類.rar
評論
共有 條評論