MATLAB image processing learning - high-pass filtering (frequency domain filtering (2))

Table of contents

1. Introduction

High-pass filter principle

effect

2. Ideal high-pass filter

3. Butterworth high-pass filter

Code (Butterworth High Pass Filter)

4. Gaussian high-pass filter


1. Introduction

High-pass filter principle:

Attenuates or rejects low-frequency components, allowing high-frequency components to pass

effect:

Make the image sharpen and highlight the border of the image.

(Note: Generally speaking, high-pass filtering has no effect on noise suppression . If high-pass filtering is simply used, the image quality may be difficult to achieve satisfactory improvement due to serious noise. In order to enhance image details and suppress noise, high Frequency enhancement filtering , which is actually composed of a high-pass filter and an all-pass filter, so that low-frequency information can be retained on the basis of high-pass filtering)

2. Ideal high-pass filter

Generate formula:

 (where D0 is the cut-off frequency of the ideal high-pass filter)

 

3. Butterworth high-pass filter

Generate formula:

 (where D0 is the cut-off frequency of the Butterworth high-pass filter, n is the order of the Butterworth filter, which is used to control the steepness of the filter)

Code (butterworth high pass filter):

clear all;clc;
I = imread('D:\resource_photo\1(1).png');

figure(1);
subplot(221),imshow(I);
title('原始图像');

k=fft2(im2double(I));
s=fftshift(fft2(im2double(I)));

subplot(222),imshow(k);
title('二维傅里叶变换后图像');
subplot(223),imshow(log(abs(s)));
title('中心频谱图像')

[a,b]=size(s);
a0=round(a/2);
b0=round(b/2);
d0=50; % 将理想高通滤波器的截止频率D0设置为50
for i=1:a %双重for循环计算频率点(i,j)与频域中心的距离D(i,j)=sqrt((i-round(a/2)^2+(j-round(b/2)^2))
    for j=1:b 
        distance=sqrt((i-a0)^2+(j-b0)^2);
        if distance<=d0  % 根据理想高通滤波器产生公式,当D(i,j)<=D0,置为0
            h=0;
        else
            h=1;        % 根据理想高通滤波器产生公式,当D(i,j)>D0,置为1
        end
        s(i,j)=h*s(i,j);% 频域图像乘以滤波器的系数
    end
end
% real函数取元素的实部
s=real(ifft2(ifftshift(s)));% 最后进行二维傅里叶反变换转换为时域图像
subplot(224),imshow(s,[]);
title('理想高通滤波所得图像');

 operation result:

 

4. Gaussian high-pass filter

Generate formula:

 (where D0 is the cutoff frequency of the Gaussian high-pass filter)

 

 

Guess you like

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