📄 originalhtml.txt
字号:
Gaussian Filter Study Matlab Codes
This program show the effect of Gaussian filter. The output are four subfigures shown in the same figure:
Subfigure 1: The initial noise free "lena"
Subfigure 2: The noisy "lena"
Subfigure 3: Filtered the initial "lena"
Subfigure 4: Filtered the noisy "lena"
The MATLAB codes:
%%%%%%%%%%%%% The main.m file %%%%%%%%%%%%%%%
clear;
% Parameters of the Gaussian filter:
n1=10;sigma1=3;n2=10;sigma2=3;theta1=0;
% The amplitude of the noise:
noise=0.1;
[w,map]=gifread('lena.gif');
x=ind2gray(w,map);
filter1=d2gauss(n1,sigma1,n2,sigma2,theta);
x_rand=noise*randn(size(x));
y=x+x_rand;
f1=conv2(x,filter1,'same');
rf1=conv2(y,filter1,'same');
figure(1);
subplot(2,2,1);imagesc(x);title('lena');
subplot(2,2,2);imagesc(y);title('noisy lena');
subplot(2,2,3);imagesc(f1);title('smooth');
subplot(2,2,4);imagesc(rf1);title('noise cancel');
colormap(gray);
%%%%%%%%%%%%%% End of the main.m file %%%%%%%%%%%%%%%
%%%%%%% The functions used in the main.m file %%%%%%%
% Function "d2gauss.m":
% This function returns a 2D Gaussian filter with size n1*n2; theta is
% the angle that the filter rotated counter clockwise; and sigma1 and sigma2
% are the standard deviation of the Gaussian functions.
function h = d2gauss(n1,std1,n2,std2,theta)
r=[cos(theta) -sin(theta);
sin(theta) cos(theta)];
for i = 1 : n2
for j = 1 : n1
u = r * [j-(n1+1)/2 i-(n2+1)/2]';
h(i,j) = gauss(u(1),std1)*gauss(u(2),std2);
end
end
h = h / sqrt(sum(sum(h.*h)));
% Function "gauss.m":
function y = gauss(x,std)
y = exp(-x^2/(2*std^2)) / (std*sqrt(2*pi));
%%%%%%%%%%%%%% End of the functions %%%%%%%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -