一維中值 均值 高斯濾波的MATLBA實現

2021-06-22 03:38:53 字數 1416 閱讀 4170

中值濾波的**:

x=0:2047;

a=load('data.txt'); %執行時data.txt檔案要放到當前目錄(current directory)中

n=5; % n為模板長度,值可以改變

y = medfilt1(a,n);

figure;

subplot(1,2,1);plot(x,a);

xlabel('中值濾波前的序列');

subplot(1,2,2);plot(x,y);

xlabel('中值濾波後的序列');

均值濾波的**:

x=0:2047;

a=load('data.txt'); %執行時data.txt檔案要放到當前目錄(current directory)中

n=5; % n為模板長度,值可以改變

mean = ones(1,n)./n; %mean為1×n的模板,各陣列元素的值均為1/n

y = conv(a,mean);

y=y(1:length(y)-length(mean)+1);

figure;

subplot(1,2,1);plot(x,a);

xlabel('均值濾波前的序列');

subplot(1,2,2);plot(x,y);

xlabel('均值濾波後的序列');

高斯濾波的**:

x=0:2047;

a=load('data.txt'); %執行時data.txt檔案要放到當前目錄(current directory)中

gau=[0.0009 0.0175 0.1295 0.3521 0.3521 0.1295 0.0175 0.0009];%標準差為1時的高斯函式一維模板,如果標準差不為1,則要修改模板

y=conv(a,gau);

y=y(1:length(y)-length(gau)+1);

figure;

subplot(1,2,1);plot(x,a);

xlabel('高斯濾波前的序列');

subplot(1,2,2);plot(x,y);

xlabel('高斯濾波後的序列');

高斯函式的一維模板可以由這個函式得到:fspecial('gaussian', [1 n], sigma)。當標準差sigma是某一固定數字時,存在乙個n,對於任意的n>=n,模板都一樣,例如:

sigma=1時,gau=[0.0009 0.0175 0.1295 0.3521 0.3521 0.1295 0.0175 0.0009]
sigma=0.5時,gau=[0.0090,0.4910,0.4910,0.0090]

二維高斯濾波器(gauss filter)的實現

我們以乙個二維矩陣表示二元高斯濾波器,顯然此二維矩陣的具體形式僅於其形狀 shape 有關 def gauss filter kernel shape 為實現二維高斯濾波器,需要首先定義二元高斯函式 f x,y 12 2exp x 2 y2 2 2 def gauss x,y,sigma 3.z 2...

白雜訊的均值一定是0嗎 均值濾波器

介紹 均值濾波器屬於低通濾波器 輸出為模板內領域畫素的簡單平均值 主要用於影象的模糊和降噪,去除尖銳部分,比濾波器模板尺寸小的畫素區域將會過濾掉 與此同時,邊緣也會被平滑 模糊。算術均值濾波器 可以去除均勻雜訊和高斯雜訊,但會對影象造成一定程度的模糊。盒狀濾波器box filter 濾波器的模板的所...

python 一維和二位資料的高斯模糊濾波

高斯分布 正態分佈 函式 高斯函式二階函式 def calc self,x,y 0 if self.level 1 return 1 2 math.pi 0.5 self.sigema math.exp x 2 2 self.sigema 2 elif self.level 2 return 1 2...