【影象去噪】基於matlab鄰域+中值濾波影象去噪【含Matlab原始碼 961期】
阿新 • • 發佈:2021-06-20
一、簡介
鄰域平均法與中值濾波法都屬於空間域影象平滑的範疇。
鄰域平均法就是對含有噪聲的原始影象f(x,y)的每一個畫素點取一個鄰域S,計算S中所有畫素灰度級的平均值,作為處理後圖像g(x,y)的畫素值,即:
中值濾波法是一種非線性處理技術,實際上就是確定一個滑動的視窗,取該視窗畫素點的中間值作為處理後圖像的畫素值。
二、原始碼
%鄰域平均法 close all;clear all;clc; a=imread('lena.jpg'); subplot(231);imshow(a);title('原圖'); b1=imnoise(a,'salt & pepper'); subplot(232);imshow(b1); title('加入椒鹽噪聲'); % b1=imnoise(a,'gaussian'); % subplot(232);imshow(b1); %title('加入高斯噪聲'); [m1,n1]=size(a); c1=b1; for i=2:m1-1 for j=2:n1-1 s=b1(i-1:i+1,j-1:j+1); end end subplot(234);imshow(c1);title('4鄰域濾波'); c2=b1; for i=2:m1-1 for j=2:n1-1 end end subplot(235);imshow(c2);title('8鄰域濾波'); c3=b1; for i=3:m1-3 for j=3:n1-3 s=b1(i-2:i+2,j-2:j+2); end end subplot(236);imshow(c3);title('12鄰域濾波'); %中值濾波 close all;clear all;clc a=imread('lena.jpg'); subplot(221);imshow(a);title('原圖'); b1=imnoise(a,'salt & pepper'); %b1=imnoise(a,'gaussian');title('加入高斯噪聲'); subplot(222);imshow(b1);title('加入椒鹽噪聲'); [m1,n1]=size(a); d1=b1; for i=2:m1-1 for j=2:n1-1 s=b1(i-1:i+1,j-1:j+1); s1=s(:);
三、執行結果
四、備註
版本:2014a
完整程式碼或代寫加1564658423