当前位置:网站首页>Digital image processing learning (II): Gaussian low pass filter

Digital image processing learning (II): Gaussian low pass filter

2022-06-26 08:32:00 Yu Getou

Introduce

  • The formula :
  1. x,y It's the coordinates of the pixels
  2. σ Is the standard deviation of normal distribution ,σ The size of will affect the final processing effect ,σ The bigger it is , The more obvious the effect of noise processing , But the more blurred the image , It is better to compare and select this value in practical application .
     Gaussian low pass filter
  • Treatment process : Similar to median filter and average filter , Gauss low-pass filtering also defines a fixed size window first ( Also known as Gaussian filter template ), Then calculate the value of each point of the template through the above formula , And then through iteration , Process each pixel of the image .

attach : The high frequency part of an image is usually edge information , Therefore, low-pass filters generally blur the image .

Code implementation

Function function

%  Gaussian low pass filter 
% img  Pass in the image 
% N_size  Defined template size , Odd value required 
% sigma  Standard deviation 
function H = GaussianLowpass(img, N_size, sigma)

%  Define the image length and width     
N_row = N_size;
N_col = N_size;

%  Gaussian filter template 
G_ry = zeros(N_row, N_col);

%  Find the center point of the image 
center = (N_size + 1) / 2;
    
%  Solution template 
for i=1 : N_row
    for j=1 : N_col
        distance_s = double((i-center-1)^2 + (j-center-1)^2);
        G_ry(i,j)=exp((-1) * distance_s/(2*sigma^2))/(2*pi*(sigma^2));
    end
end

%  Image filtering 
H = imfilter(img,G_ry);

end

The main function

%  Load Images 
img = imread("photo.jpeg");

%  Image binarization 
img = rgb2gray(img);

%  Gauss filtering 
G_img = GaussianLowpass(img, 15, 1.2);

%  Draw pictures before and after processing 
figure; 
imshow(img); 
title(" Original picture ");

figure; 
imshow(G_img); 
title(" Gauss filter effect picture ");

Effect display

 Insert picture description here

原网站

版权声明
本文为[Yu Getou]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170556033759.html