# 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.[1]

 This article appears to have insufficient references to demonstrate notability. However, an editor has performed a search and claims that there are sufficient sources to indicate that this is a notable topic. (October 2020)

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.

## . . . Guided filter . . .

One key assumption of the guided filter is that the relation between guidance

${displaystyle I}$

and the filtering output

${displaystyle q}$

is linear. Suppose that

${displaystyle q}$

is a linear transformation of

${displaystyle I}$

in a window

${displaystyle omega _{k}}$

centered at the pixel

${displaystyle k}$

.

In order to determine the linear coefficient

${displaystyle (a_{k},b_{k})}$

, constraints from the filtering input

${displaystyle p}$

are required. Model the output

${displaystyle q}$

as the input

${displaystyle p}$

subtract some unwanted components

${displaystyle n}$

, such as noise/textures.

The following is the basic model of the guided image filter：

(1)

${displaystyle q_{i}=a_{k}I_{i}+b_{k},forall iin omega _{k}}$

(2)

${displaystyle q_{i}=p_{i}-n_{i}}$

In the above formula:

${displaystyle q_{i}}$

is the

${displaystyle i_{th}}$

output pixel;

${displaystyle p_{i}}$

is the

${displaystyle i_{th}}$

input pixel;

${displaystyle n_{i}}$

is the

${displaystyle i_{th}}$

pixel of noise components;

${displaystyle I_{i}}$

is the

${displaystyle i_{th}}$

guidance image pixel;

${displaystyle (a_{k},b_{k})}$

are some linear coefficients assumed to be constant in

${displaystyle omega _{k}}$

.

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

${displaystyle q}$

has an edge only if

${displaystyle I}$

has an edge, since

${displaystyle nabla q=anabla I}$

.

Subtract (1) and (2) to get formula (3)；At the same time, define a cost function (4)：

(3)

${displaystyle n_{i}=p_{i}-a_{k}I_{i}-b_{k}}$

(4)

${displaystyle E(a_{k},b_{k})=sum _{i{epsilon }{omega }_{k}}^{}((a_{k}I_{i}+b_{k}-p{i})^{2}+{epsilon }a_{k}^{2})}$

In the above formula:

${displaystyle epsilon }$

is a regularization parameter penalizing large

${displaystyle a_{k}}$

;

${displaystyle omega _{k}}$

is a window centered at the pixel

${displaystyle k}$

.

And the cost function’s solution is given by：

(5)

${displaystyle a_{k}={frac {{frac {1}{left|omega right|}}sum _{iepsilon omega _{k}}I_{i}p_{i}-mu _{k}{bar {p_{k}}}}{sigma _{k}^{2}+epsilon }}}$

(6)

${displaystyle b_{k}={bar {p_{k}}}-a_{k}mu _{k}}$

In the above formula:

${displaystyle mu _{k}}$

and

${displaystyle sigma _{k}^{2}}$

are the mean and variance of

${displaystyle I}$

in

${displaystyle omega _{k}}$

;

${displaystyle left|omega right|}$

is the number of pixels in

${displaystyle omega _{k}}$

;

${displaystyle {bar {p}}_{k}={frac {1}{left|omega right|}}sum _{iepsilon omega _{k}}p_{i}}$

is the mean of

${displaystyle p}$

in

${displaystyle omega _{k}}$

.

After obtaining the linear coefficients

${displaystyle (a_{k},b_{k})}$

, we can calculate the filtering output

${displaystyle q_{i}}$

by (1)