The two-dimensional Gaussian function has the Rotation Symmetry. After processing, it does not perform excessive filtering on the edge in any direction. Therefore, compared with other filters, it has incomparable superiority. However, with the increase of the image size, the traditional Gauss filter increases the computational complexity by square, so it is necessary to optimize and improve it. The following describes three implementation methods: traditional, factorization, and recursive iteration.
1 traditional type
First, a Gauss filter core needs to be constructed for Gauss filtering. The formula is as follows:
MATLAB implementationCode:
Dsigma = 0.8; fk1 = 1.0/(2 * dsigma); fk2 = fk1/PI; isize = 5; step = floor (isize/2 + 0.5 ); for I = 1: isize x = I-step; ftemp = fk2 * exp (-x * fk1); for j = 1: isize y = J-step; model (x + step, Y + step) = ftemp * exp (-y * fk1); endenddsum = sum (model); Model = model/dsum; % Gauss kernel value Normalization
Figure 1 Gauss filter core (5x5)
The next step is to perform convolution for the input image and the filter core. The essence is to weighted sum the original image and assign the sum to the central pixel. For an image of 2048*2048, 104734756 multiplication operations and 104734756 addition operations are required. The operation complexity is very high.
2. decomposition type
We can break down a two-dimensional Gauss kernel into two one-dimensional Gaussian kernels, perform a one-dimensional convolution on the rows, and then perform a one-dimensional column convolution on the convolution results. The results are exactly the same, the overhead is much smaller.
One-dimensional Gaussian Kernel functions:
Matlab code implementation:
Dsigma = 0.8; fk1 = 1.0/(2 * dsigma); fk2 = fk1/PI; isize = 5; step = floor (isize/2 + 0.5 ); for I = 1: isize x = I-step; ftemp = fk2 * exp (-x * fk1); Model (1, x + step) = ftemp; enddm = sum (model); Model = model/DM;
Figure 2 one-dimensional Gaussian filter kernel (1*5)
The principle of one-dimensional convolution is the same as that of two-dimensional convolution, except that we only need to add the data in the same row or column to the center element by position-weighted sum.
For an image of 2048*2048, 41918464 multiplication operations and 41918464 addition operations are required. Compared with traditional computing, it is only 1/2. 4985 of the former. If the Gauss filter is frequently calculatedAlgorithmThe latter is much faster than the former.
3. Recursive iteration type
The second method is more complex than the first method, although it has been greatly improved. Here we will introduce a more rapid approach to Gaussian filtering.
The specific steps are divided into two steps: first, perform a forward filter on the image, and then perform a backward filter on the image.
Forward:
Backward:
Reference: Recursive Implementation of the Gaussian filter. Ian T. Young, 1995