Digital image processing---Basics of spatial filtering

Spatial filtering concept
  1. Filtering: By modifying or suppressing specific frequency components of a given image, low-pass filters and high-pass filters are common.
  2. Spatial filtering: Replace the pixel value with the value of the pixel value and its neighborhood. There are two replacement methods: linear filter and nonlinear filter.
linear filter

The general method is to use a matrix (also called a kernel) to perform a similar convolution operation with the image to do the product.
The values ​​inside the matrix determine the function of the filter.

(The picture below is from Digital Image Processing 4th Edition=DIGITAL IMAGE PROCESSING,FOURTH EDITION)
Insert image description here

separable filter core

Decompose a 2D matrix into the product of two 1D vectors.
G ( X , Y ) = G 1 ( X ) G 2 ( Y ) G(X,Y)=G_1(X)G_2(Y)G(X,Y)=G1(X)G2( Y )

w = [ 1 1 1 1 1 1 1 1 ] w=\begin{equation} \left[\begin{array}{ccc} 1 & 1 & 1 \\ 1 & 1 & 1 \\ & 1 & 1 \ end { array } \ right ] \ end { equation }w= 111111111
Defaults
1 = [ 1 1 1 ] w 2 = [ 1 1 1 ] w_1=\begin{equation} \left[\begin{array}{ccc} 1 \\ 1 \\ 1 \end{array}\ right ] \ end { equation } \hspace { 1.5cm } w_2= \ begin { equation } \ left [ \ begin { array } {ccc } 1 & 1 & 1 \ \ end { array } \ right ] \ end { equation } }w1= 111 w2=[111]
The product of the two.

PS:判断一个核是否是可分离卷积核,即判断该卷积核是否是秩为1.若为1,即可分离,否则不可。

The benefit of convolution being separable:
Assume the image size is M ∗ NM*NMN , the convolution kernel size ism ∗ nm*nmn , the calculation amount of direct convolution includesMN mn MNmnMN mn times multiplication andMN mn MNmnMN mn additions. If separable convolution is used,www minutew 1 ∗ w 2 w_1*w_2w1w2, and w 1 w_1w1is m ∗ 1 m*1m1 w 2 w_2 w2is 1 ∗ n 1*n1n , combine the image matrix withw 1 w_1w1sum w 2 w_2w2Do convolution separately to get the amount of operation: MN m + MN n MNm+MNnMN m+MN n,即MN ( m + n ) MN(m+n)MN ( m+n ) . Compared to the previousMN mn MNmnMN mn , greatly reducing the amount of calculation.

Determination of separable vectors:
According to the properties of the matrix, for a matrix with rank 1, the difference between each row is only a constant multiple, and the difference between each column is only a constant multiple. Then we can find any row and column to solve. Of course It is necessary to ensure that both the row and column are non-zero vectors.

filter type
linear filter
  1. Low pass spatial filter
    \hspace{0.5cm}It mainly acts on areas that change slowly, such as smooth floors; table edges, etc. are high-frequency areas.
    1.1 Box filter kernel
    \hspace{0.5cm}The value of this filter kernel is all 1, which can produce a smooth effect on the picture.
    1.2 Low-pass Gaussian filter kernel
    \hspace{0.5cm}高斯核 w ( s , t ) = G ( s , t ) = K e − s 2 + t 2 2 σ 2 w(s,t) = G(s,t)=Ke^{-\frac{s^2+t^2}{2\sigma^2}} w(s,t)=G(s,t)=K e2 p2s2+t2
    \hspace{0.5cm} Among them sss andttt is the coordinate (with the core as the origin),( s 2 + t 2 ) 1 2 (s^2+t^2)^{\frac{1}{2}}(s2+t2)21is the distance to the original center.
    Insert image description here
    In particular, the Gaussian kernel is also separable.

  2. High pass filter
    \hspace{0.5cm}Act on images through edge enhancement and other methods.

nonlinear filter
  1. Median filter
    \hspace{0.3cm}Sort a certain pixel and the pixels in its neighborhood. The value of the central pixel is determined by the intermediate value of the sorted pixels in the neighborhood. It is especially effective in eliminating salt and pepper noise.
  2. Maximum filter and minimum filter
    \hspace{0.3cm}Maximum filter: sorts a pixel and the pixels in its neighborhood. The value of the center pixel is determined by the maximum sorted pixel value in the neighborhood.
    \hspace{0.3cm}Minimum filter: Sorts a pixel and the pixels in its neighborhood. The value of the center pixel is determined by the maximum sorted pixel value in the neighborhood.
  3. Midpoint filter
    \hspace{0.3cm}Sort a pixel and the pixels in its neighborhood. The central pixel value is determined by the average of the maximum value and the minimum value. It is suitable for processing randomly distributed noise, such as Gaussian noise or uniform noise.
  4. Otherwise A lpha AlphaA l pha mean filter
    \hspace{0.3cm}An improvement on the median filter, which deletes part of the lowest gray value and the highest gray value from a certain pixel and its neighborhood, and calculates the arithmetic mean of the remaining pixel values ​​as the central pixel value, which is suitable for processing mixed noise , such as a mixture of salt-and-pepper noise and Gaussian noise.
adaptive filter

Adaptation focuses on considering changes in different feature points of the image.

  1. Adaptive local noise reduction filter
    \hspace{0.3cm}The parameters that need to be considered for this filter involve the image pixel value and noise variance with noise; the local pixel mean and local variance in the filter.
    The pixel value of the image with noise is f (x, y) f(x,y)f(x,y ) , the noise variance isσ f \sigma_fpf, the local mean is fxy ^ \hat{f_{xy}}fxy^, the local variance is σ xy \sigma_{xy}pxy
    The calculation method of the four parameters can be obtained by multiplying the frequency and correlation value of the histogram.
    The adaptive expression is f ˉ ( x , y ) = f ( x , y ) − σ f 2 σ xy 2 [ f ( x , y ) − fxy ^ ] \bar{f}(x,y)=f (x,y)-\frac{\sigma_f^2}{\sigma_{xy}^2}[f(x,y)-\hat{f_{xy}}]fˉ(x,y)=f(x,y)pxy2pf2[f(x,y)fxy^]
    The characteristic of this formula is
    \hspace{0.6cm}If the variance of the noise is 0, the filtering result is f (x, y) f(x,y)f(x,y)
    \hspace{0.6cm} If the variance of the noise is equal to the local variance, the filtering result is the mean of the local pixel values ​​of the image;
  2. Adaptive median filter
    \hspace{0.3cm}Optimization of median filtering
    Smoothes non-impulsive noise (non-dramatic changes) while preserving image details
    Similar to the adaptive local noise reduction filter, calculations are performed in local areas.
    In the local area, zmin z_{min}zminRepresents the minimum gray value, zmax z_{max}zmaxRepresents the maximum gray value, zmed z_{med}zm e dRepresents the median gray value, zxy z_{xy}zxyis the coordinate (x, y) (x,y)(x,The gray value at y ) , S max S_{max}SmaxIndicates the size of the local area.
    Algorithm steps:
    1. zmin z_{min}zmin < z m e d z_{med} zm e d< z m a x z_{max} zmax, then go to the second step; otherwise, increase the local area size, if the local area size is less than S max S_{max}Smax, repeat step 1, otherwise output zmed z_{med}zm e d
    2. zmin z_{min}zmin < z x y z_{xy} zxy< z m a x z_{max} zmax, then output zxy z_{xy}zxy, otherwise output zmed z_{med}zm e d
      The main idea of ​​the algorithm is to eliminate impulse noise through two layers of judgment. If you switch from the first step to the second step, zmed z_{med} can be guaranteedzm e dis non-impulsive noise; in the second step, regardless of the output zmed z_{med}zm e dOr zxy z_{xy}zxyAll achieved the purpose of eliminating impulse noise. But if the output ends up in the first step, there is no guarantee that zmed z_{med}zm e dWhether it is impulse noise.
      PS:所以该算法旨在尽力消除,不保证全部消除。

Guess you like

Origin blog.csdn.net/qq_44116998/article/details/128723099