[Digital Image Processing Learning Essay] Image Transformation

digital image processing


1. Introduction to image transformation

1.1 Purpose of image transformation

  1. Simplify image processing problems;
  2. Conducive to image feature extraction;
  3. Helps conceptually enhance understanding of image information.

1.2 Requirements for image transformation

Image transformation is usually a two-dimensional orthogonal transformation. General requirements:

  1. Orthogonal transformations must be reversible;
  2. The algorithms of forward transformation and inverse transformation cannot be too complex;
  3. The characteristic of orthogonal transformation is that in the transformation domain, image energy will be concentrated on low-frequency components, and edge and linear information will be reflected on high-frequency components, which is beneficial to image processing.

1.3 Frequency domain filtering

Frequency domain filtering is actually a way of image transformation. Simply put, it isThe original image is first converted to the frequency domain, and the spectrum of the original image is processed in the frequency domain. The image after frequency domain processing is then inversely transformed in the frequency domain and converted back to the spatial domain., thereby achieving the purpose of processing the original image.

1.4 Why image processing should be performed in the frequency domain

The key to image processing in the frequency domain is the relationship between the frequency plane and the spatial domain characteristics of the image.
In the frequency domain space, the part of the image that changes gently is close to the center of the frequency plane, and this area is the low-frequency area.
The edges, noise, and steeply changing parts of the image leave the center of the frequency plane in the radial direction. This area is a high-frequency area.
Insert image description here


2. Basic principles of frequency domain enhancement

In the frequency space, the information of the image is expressed ascombination of different frequency componentsIf frequency components within a certain range can be suppressed while leaving other components unaffected, the frequency distribution of the output image can be changed to achieve different enhancement purposes.
Insert image description here


3. Basic steps of frequency domain filtering

The schematic diagram of frequency domain filtering is shown in the figure below.
Insert image description here
The steps of frequency domain filtering are shown in the figure below.
Insert image description here


4. Low-pass (smoothing) filter

4.1 Basic idea of ​​frequency domain smoothing filter

The edges and other parts with drastic grayscale changes in the image are mainly in the high-frequency part after Fourier transform.
Smoothing can be achieved by attenuating the range of high-frequency components in the Fourier transform of a specified image.
There are three main types of low-pass smoothing filters introduced here, namely ideal low-pass filter, Butterworth low-pass filter, and Gaussian low-pass filter.

4.2 Comparison of three low-pass filters

4.2.1 Ideal low-pass filter (ILPF)
ideal low pass filter
Ideal - means that frequencies less than D0 can pass through the filter completely unaffected, while frequencies greater than D0 can pass through the filter completely. Can't pass.

advantage:

  • Within the circle with radius D0, all frequencies pass through the filter without attenuation, while all frequencies outside the circle with this radius are completely attenuated.
    Disadvantages:
  • Since high-frequency components contain a large amount of edge information, using this filter to remove noise will result in loss of edge information and blur the image.
  • Ringing effect: Appears on a 2-D image as a series of concentric rings; the ring radius is inversely proportional to the cutoff frequency.
  • This is not possible in practice.

4.2.2 Butterworth Low Pass Filter (BLPF)
Butterworth filter
Advantages:

  • Physically achievable (the ideal low-pass filter is clearly defined mathematically and can be realized in computer simulations, but the ideal low-pass filter that goes straight up and down at the cutoff frequency cannot be realized with actual electronic devices).
  • The ringing effect is reduced and the transition between high and low frequencies is smoother.
  • Compared with an ideal filter, this filter can greatly reduce the blurring of image edges while suppressing noise.

Disadvantages: When the order is very high, the smoothing effect is great, but the ringing effect is also more obvious, and the smoothing effect will be weakened.

Purpose: When images produce false contours due to insufficient quantization, they can often be smoothed with low-pass filtering to improve image quality.

4.2.3 Gaussian Low Pass Filter (GLPF)
Gaussian low pass filter
Advantages:

  • The inverse Fourier transform of a Gaussian low-pass filter is also Gaussian, which also means that the spatial Gaussian filter obtained by calculating the inverse Fourier transform of the above equation will have no ringing.

shortcoming:

  • GLPF cannot achieve the smoothing effect of the second-order BLPF with the same cutoff frequency.
  • If you need to strictly control the transition between low frequency and high frequency, choose BLPF, but the cost is the possibility of ringing.

5. MATLAB code implementation

5.1 Ideal low-pass filter

%%%%%%%%%%%%% 理想 %%%%%%%%%%%%%%%%%%%%%%
s=fftshift(fft2(im2double(I)));
[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,置为1
            h=1;
        else
            h=0;        % 根据理想低通滤波器产生公式,D(i,j)>D0,置为0
        end
        s(i,j)=h*s(i,j);% 频域图像乘以滤波器的系数
    end
end
% real函数取元素的实部
s=real(ifft2(ifftshift(s)));% 最后进行二维傅里叶反变换转换为时域图像
subplot(2,3,4),imshow(s,[]);
title('理想低通滤波所得图像'); 

5.2 Butterworth filter

%%%%%%%%%%%%% Butterworth %%%%%%%%%%%%%%%%%%%%%%
s=fftshift(fft2(im2double(I)));
[N1,N2]=size(s);%求二维傅里叶变换后图像大小
n=2;            % 将巴特沃斯低通滤波器的阶数n设置为2
d0=50;          % 将巴特沃斯低通滤波器的截止频率D0设置为50
n1=round(N1/2);
n2=round(N2/2);
for i=1:N1      %双重for循环计算频率点(i,j)与频域中心的距离D(i,j)=sqrt((i-round(N1/2)^2+(j-round(N2/2)^2))
    for j=1:N2 
        distance=sqrt((i-n1)^2+(j-n2)^2);
        if distance==0 
            h=0; 
        else
            h=1/(1+(distance/d0)^(2*n));% 根据巴特沃斯低通滤波器公式为1/(1+[D(i,j)/D0]^2n)
        end
        s(i,j)=h*s(i,j);% 频域图像乘以滤波器的系数
    end
end
% real函数取元素的实部
s=real(ifft2(ifftshift(s)));% 最后进行二维傅里叶反变换转换为时域图像
subplot(2,3,5),imshow(s,[]);
title('Butterworth低通滤波图像');

5.3 Gaussian low-pass filter

%%%%%%%%%%%%% Gaussian %%%%%%%%%%%%%%%%%%%%%%
s=fftshift(fft2(im2double(I)));
[a,b]=size(s);
d0=50; % 将高斯低通滤波器的截止频率D0设置为50
a1=round(a/2);
b1=round(b/2);
for i=1:a
    for j=1:b
        distance=sqrt((i-a0)^2+(j-b0)^2);    % 根据高斯低通滤波器公式H(u,v)=e^-[D^2(u,v)/2*D0^2] 
        h=exp(-(distance*distance)/(2*(d0^2))); % exp表示以e为底的指数函数
        s(i,j)=h*s(i,j);% 频域图像乘以滤波器的系数
    end
end

s=real(ifft2(ifftshift(s)));% 最后进行二维傅里叶反变换转换为时域图像
subplot(2,3,6),imshow(s,[]); 
title('高斯低通滤波图像');

Guess you like

Origin blog.csdn.net/The___sky_/article/details/128469481