MATLAB learning - low-pass filtering (frequency domain filtering (1))

Table of contents

1. Introduction

2. Low-pass filtering

(1) Ideal low-pass filter

    Code (ideal low pass filter)

(2) Butterworth low-pass filter

   Code (Butterworth low pass filter)

(3) Gaussian low-pass filter

 


1. Introduction

Frequency domain image enhancement first converts the image from the spatial domain to the frequency domain through Fourier transform, processes the image in the frequency domain, and then converts the image to the spatial domain by inverse Fourier transform after processing.

Frequency domain filtering mainly includes low-pass filtering, high-pass filtering, and homomorphic filtering.

2. Low-pass filtering

Lets low frequencies pass, while filtering or attenuating high frequencies. The function is to filter out the noise contained in the high frequency. Therefore, the effect of low-pass filtering is image denoising and smooth enhancement.

(1) Ideal low-pass filter

Within the radius D0, all frequencies pass the filter without attenuation, but all frequencies outside the radius are attenuated.

    Code (ideal low pass filtering):

close all;clear all;clc;
I=imread('D:\resource_photo\3.png');
I=im2double(I);
M=2*size(I,1);  %滤波器行数
N=2*size(I,2);  %滤波器列数
u=-M/2:(M/2-1);
v=-N/2:(M/2-1);
[U,V]=meshgrid(u,v);
D=sqrt(U.^2+V.^2);
D0=60;  %截止频率
H=double(D<=D0); %理想低通滤波
J=fftshift(fft2(I,size(H,1),size(H,2))); %时域图像转换到频域
K=J.*H;  %滤波处理
L=ifft2(ifftshift(K)); %傅里叶反变换
L=L(1:size(I,1),1:size(I,2));
figure;
subplot(121);imshow(I)
subplot(122);imshow(L)

(2) Butterworth low-pass filter

Generate formula:

Among them, D0 is the cut-off frequency of the Butterworth low-pass filter, and the parameter n is the order of the Butterworth filter. The larger n is, the steeper the shape of the filter is.

   Code (butterworth low pass filtering):

close all;clear all;clc;
I=imread('D:\resource_photo\3.png');
I=im2double(I);
M=2*size(I,1);  %滤波器行数
N=2*size(I,2);  %滤波器列数
u=-M/2:(M/2-1);
v=-N/2:(M/2-1);
[U,V]=meshgrid(u,v);
D=sqrt(U.^2+V.^2);
D0=50;  %截止频率
n=6; %滤波器的阶数
H=1./(1+(D./D0).^(2*n)); %巴特沃斯滤波器
J=fftshift(fft2(I,size(H,1),size(H,2))); %时域图像转换到频域
K=J.*H;  %滤波处理
L=ifft2(ifftshift(K)); %傅里叶反变换
L=L(1:size(I,1),1:size(I,2));
figure;
subplot(121);imshow(I)
subplot(122);imshow(L)

(3) Gaussian low-pass filter

Generate formula:

 Where D0 is the cut-off frequency of the Gaussian low-pass filter.

 

 

 

Guess you like

Origin blog.csdn.net/weixin_52135595/article/details/126970096