[Digital Image Processing and Application] Using first-order Butterworth low-pass filter for frequency domain filtering

topic

  1. Given the image 'barb.png', use the first-order Butterworth low-pass filter for frequency domain filtering, when D 0 = 10 , 20 , 40 , 80 D_0=10,20,40,80D0=10,20,40,At 80 pm , the corresponding filtered image is given, and the relevant filtering results are explained from the perspectives of frequency domain and spatial domain respectively.
    Tips:
    (1) Take( − 1 ) x + y (-1)^{x+y}(1)Multiply x + y by the input image for center transformation;
    (2) Directly perform Fourier transform with FFT2;
    (3) Take the real part after inverse DFT transformation;
    (4) Use( − 1 ) x + y (-1)^{x +y}(1)x + y multiplied by the result in (3), inverse central transformation.
    Insert image description here

Matlab code implementation

Algorithm introduction


This algorithm description document aims to explain how to use the first-order Butterworth low-pass filter to perform frequency domain filtering on a given image . By setting different cutoff frequencies D0 (with values ​​of 10, 20, 40 and 80), we will generate corresponding filtered
images and interpret the filtering results from the frequency domain and spatial domain perspectives.

Algorithm steps

  1. Import image: Import the image barb.png to be processed, and use the imread function to read the image into matrix form.
  2. Grayscale: Use the im2gray function to convert a color image into a grayscale image. This will cause the image to become single channel during processing.
  3. Normalization: Use the im2double function to convert the pixel values ​​of the grayscale image into double-precision floating point numbers, and normalize the pixel values ​​to [0, 1] [0,1][0,1 ] within the range.
  4. Get the image size: Use the size function to get the size of the grayscale image, and store the width and height as MM respectively.M andNNN
  5. Center transformation: Convert the normalized grayscale image to a vector consisting of ( − 1 ) x + y (-1)^{x+y}(1)Multiply the matrices composed of x + y , where xxxyyy represents the abscissa and ordinate of the pixel respectively. This step moves the image from the center of the spatial domain to the center of the frequency domain.
  6. Fourier transform: use fft 2 \mathrm{fft} 2The fft 2 function performs a two-dimensional Fourier transform on the center-transformed image to obtain a complex representation in the frequency domain.
  7. Generate Butterworth low-pass filter: according to the given cutoff frequency D 0 D_0D0, generate a Butterworth low-pass filter H. HH. HH. _ The size of H is the same as the size of the image, where each position(u, v) (u, v)(u,The value at v ) is 1 1 + ( u D 0 ) 2 + ( v D 0 ) 2 \frac{1}{1+\left(\frac{u}{D_0}\right)^2+\left( \frac{v}{D_0}\right)^2}1+(D0u)2+(D0v)21
  8. Filtering: Multiply the Fourier transform result and the Butterworth filter element by element to obtain the filtered frequency domain result.
  9. Inverse central transformation: The filtered frequency domain result is again combined with a function given by ( − 1 ) x + y (-1)^{x+y}(1)Multiply matrices consisting of x + y to perform an inverse central transformation.
  10. Spatial domain result: Take the real part of the result after the anti-center transformation and restore the pixel value to the original range to obtain the filtering result in the spatial domain.
  11. Output the filtered spatial image.

Matlab code

img = imread('barb.png');
img_gray = im2gray(img);
img_gray = im2double(img_gray);
[M, N] = size(img_gray);

figure('Name', '频域滤波结果');

D0_values = [10, 20, 40, 80];

for i = 1:length(D0_values)
    D0 = D0_values(i);
    
    % 中心变换
    centered_img = img_gray .* (-1).^(meshgrid(1:N) + meshgrid(1:M)');
    
    % 傅立叶变换
    F = fft2(centered_img);
    
    % 生成Butterworth低通滤波器
    H = 1 ./ (1 + (meshgrid(-(N/2):(N/2-1)).^2 + meshgrid(-(M/2):(M/2-1)).^2) / D0^2);
    
    % 滤波
    filtered_img = real(ifft2(F .* H));
    
    % 反中心变换
    filtered_img = filtered_img .* (-1).^(meshgrid(1:N) + meshgrid(1:M)');
    
    % 显示频域结果
    subplot(2, length(D0_values), i);
    imshow(log(1 + abs(fftshift(F))), []);
    title(['频域 (D0 = ' num2str(D0) ')']);
    
    % 显示空域结果
    subplot(2, length(D0_values), i + length(D0_values));
    imshow(filtered_img, []);
    title(['空域 (D0 = ' num2str(D0) ')']);
end

operation result

Insert image description here

  • According to the comparison in the above figure, we can see that when using a first-order Butterworth low-pass filter to filter in the frequency domain, the value of D0 has a significant impact on the filtering effect. Specifically, as the D0
    value increases, the filtered image becomes clearer. This is because as D0 increases, fewer high-frequency components are filtered out, so the clarity of the image is improved.
  • In the spatial domain, the role of the filter is to reduce high-frequency noise in the image. However, the size selection of D0 will also affect the degree to which the high-frequency components of the image itself are lost. If D0
    is chosen too small, more details will be lost in the image. Therefore, when using filters, we need to choose an appropriate D0 value according to the actual situation to achieve the best filtering effect.
  • In the frequency domain, the center part of the frequency domain image after center transformation is the low-frequency part, and this part of the content will be retained by the filter. The farther out the high frequency part is, the easier it is to be filtered out. Therefore, the filtered frequency domain image content is basically concentrated near the center, which is why
    the image clarity increases as D0 increases.
  • In general, the first-order Butterworth low-pass filter plays an important role in frequency domain filtering. By rationally selecting the D0
    value, we can effectively reduce the high-frequency noise in the image while retaining the main information of the image.

Download code and related documents

https://download.csdn.net/download/weixin_66397563/88067734

Disclaimer: Please do not reproduce without permission

Guess you like

Origin blog.csdn.net/weixin_66397563/article/details/131829177