Guided filter

Guided filter is a kind of edge-preserving smoothing filter. Same as bilateral filter, this image filter can also filter out noise or texture while retaining sharp edges.
Unlike the bilateral filter, the guided image filter has two advantages: first, Bilateral filters have very high computational complexity, but the guided image filter does not use too complicated mathematical calculations which has linear computational complexity. Furthermore, due to the mathematical model, bilateral filters sometimes have unwanted gradient reversal artifacts and cause image distortion. While the guided image filter, since the filter is mathematically based on linear combination, the output image must be consistent with the gradient direction of the guidance image, and the problem of gradient reversal does not occur.
Definition.
One key assumption of the guided filter is that the relation between guidance formula_1 and the filtering output formula_2 is linear. Suppose that formula_2 is a linear transformation of formula_1 in a window formula_5 centered at the pixel formula_6.
In order to determine the linear coefficient formula_7, constraints from the filtering input formula_8 are required. Model the output formula_2 as the input formula_8 subtract some unwanted components formula_11, such as noise/textures.
The following is the basic model of the guided image filter：
(1)　　formula_12
(2)　　formula_13
In the above formula:
The reason to define as linear combination is that the boundary of an object is related to its gradient. The local linear model ensures that formula_2 has an edge only if formula_1 has an edge, since formula_26.
Subtract (1) and (2) to get formula (3)；At the same time, define a cost function (4)：
(3)　　formula_27
(4)　　formula_28
In the above formula:
And the cost function's solution is given by：
(5)　　formula_33
(6)　　formula_34
In the above formula:
After obtaining the linear coefficients formula_7, we can calculate the filtering output formula_45 by (1)
Algorithm.
By definition, the algorithm can be written as:
Algorithm 1. Guided Filter
input： filtering input image formula_8 ，guidance image formula_1 ，window radius formula_48 ，regularization formula_29
output： filtering output formula_2
1.
 formula_51 = formula_52
 formula_53 = formula_54
 formula_55 = formula_56
 formula_57 = formula_58
2.
 formula_59 = formula_60
 formula_61 = formula_62
3.
 formula_63 = formula_64
 formula_65 = formula_66
4.
 formula_67 = formula_68
 formula_69 = formula_70
5.
 formula_2 = formula_72
formula_73 is a mean filter with a wide variety of O(N) time methods.
Properties.
When the guidance image formula_1 is the same as the filtering input formula_8. The guided filter will filter out noise in the input image while preserving clear edges.
Specifically, one can define what is a “flat patch” or a “high variance patch” by the parameter formula_29 of the guided filter. Those patches with variance much lower than the parameter formula_29 will be smoothed, and those with variances much higher than formula_29 will be preserved. The role of the range variance formula_79 in the bilateral filter is similar to formula_29 in the guided filter. Both of them define “where are the edge/a high variance patches that should be kept. what is noise/flat patch that should be smoothed.”
When using the bilateral filter to filter an image, some artifacts may appear on the edges. This is because the pixel value abrupt change on the edge. These artifacts are inherent and hard to avoid, because edges usually appear in all kinds of pictures.
The guided filter performs better in avoiding gradient reversal. Moreover, in some cases, it can be ensured that gradient reversal does not occur.
Due to the local linear model of formula_81, it is possible to transfer the structure from the guidance formula_1 to the output formula_2. This property enables some special filtering-based applications, such as feathering, matting and dehazing.