Guided filter explained

A guided filter is an edge-preserving smoothing image filter. As with a bilateral filter, it can filter out noise or texture while retaining sharp edges.[1] [2]

Comparison

Compared to the bilateral filter, the guided image filter has two advantages: bilateral filters have high computational complexity, while the guided image filter uses simpler calculations with linear computational complexity. Bilateral filters sometimes include unwanted gradient reversal artifacts and cause image distortion. The guided image filter is based on linear combination, making the output image consistent with the gradient direction of the guidance image, preventing gradient reversal.

Definition

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

I

and the filtering output

q

is linear. Suppose that

q

is a linear transformation of

I

in a window

\omegak

centered at the pixel

k

.

In order to determine the linear coefficient

(ak,bk)

, constraints from the filtering input

p

are required. The output

q

is modeled as the input

p

with unwanted components

n

, such as noise/textures subtracted.

The basic model:

(1)  

qi=akIi+bk,\foralli\in\omegak

(2)  

qi=pi-ni

in which:

qi

is the

ith

output pixel;

pi

is the

ith

input pixel;

ni

is the

ith

pixel of noise components;

Ii

is the

ith

guidance image pixel;

(ak,bk)

are some linear coefficients assumed to be constant in

\omegak

.

The reason to use a linear combination is that the boundary of an object is related to its gradient. The local linear model ensures that

q

has an edge only if

I

has an edge, since

\nablaq=a\nablaI

.

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

(3)  

ni=pi-akIi-bk

(4)  

E(ak,bk)=\sumi{\epsilon{\omega}k

}^((a_I_ + b_ - p_)^ + a_^)

in which

\epsilon

is a regularization parameter penalizing large

ak

;

\omegak

is a window centered at the pixel

k

.

And the cost function's solution is:

(5)  

ak=

1
\sum
i\epsilon\omegak
Iipi-\muk\bar{pk
\left|\omega\right|
}

(6)  

bk=\bar{pk

} - a_\mu_

in which

\muk

and
2
\sigma
k
are the mean and variance of

I

in

\omegak

;

\left|\omega\right|

is the number of pixels in

\omegak

;

\bar{p}k=

1
\left|\omega\right|
\sum
i\epsilon\omegak

pi

is the mean of

p

in

\omegak

.

After obtaining the linear coefficients

(ak,bk)

, the filtering output

qi

is provided by the following algorithm:

Algorithm

By definition, the algorithm can be written as:

Algorithm 1. Guided Filter

input: filtering input image

p

,guidance image

I

,window radius

r

,regularization

\epsilon

output: filtering output

q

1.

meanI

=

fmean(I)

meanp

=

fmean(p)

corrI

=

fmean(I.*I)

corrIp

=

fmean(I.*p)

2.

varI

=

corrI-meanI.*meanI

covIp

=

corrIp-meanI.*meanp

3.

a

=

covIp./(varI+\epsilon)

b

=

meanp-a.*meanI

4.

meana

=

fmean(a)

meanb

=

fmean(b)

5.

q

=

meana.*I+meanb

fmean

is a mean filter with a wide variety of O(N) time methods.

Properties

Edge-preserving filtering

When the guidance image

I

is the same as the filtering input

p

. The guided filter removes noise in the input image while preserving clear edges.

Specifically, a “flat patch” or a “high variance patch” can be specified by the parameter

\epsilon

of the guided filter. Patches with variance much lower than the parameter

\epsilon

will be smoothed, and those with variances much higher than

\epsilon

will be preserved. The role of the range variance
2
\sigma
r
in the bilateral filter is similar to

\epsilon

in the guided filter. Both of them define the edge/high variance patches that should be kept and noise/flat patches that should be smoothed.”

Gradient-preserving filtering

When using the bilateral filter to filter an image, artifacts may appear on the edges. This is because of the pixel value's abrupt change on the edge. These artifacts are inherent and hard to avoid, because edges 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.

Structure-transferring filtering

Due to the local linear model of

q=aI+b

, it is possible to transfer the structure from the guidance

I

to the output

q

. This property enables some special filtering-based applications, such as feathering, matting and dehazing.

Implementations

See also

Notes and References

  1. He . Kaiming . Sun . Jian . Xiaoou . Tang . 2013 . Guided Image Filtering. 35 . 6 . 1397–1409 . 10.1109/TPAMI.2012.213. IEEE Transactions on Pattern Analysis and Machine Intelligence .
  2. https://web.archive.org/web/20170323172320/http://www.jiansun.org/papers/GuidedFilter_ECCV10.pdf Guided Image Filtering
  3. Web site: Guided filtering of images - MATLAB imguidedfilter.
  4. Web site: OpenCV: Filters.
  5. Web site: FFmpeg Filters Documentation.