Guided filter
A guided filter is an edge-preserving smoothing image filter.
≈ 4 min read
Guided filter. encyclopegia.org, snapshot enwiki-001258164511. /a/guided-filter
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
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
edit edit sourceCompared 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
edit edit sourceOne 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 ωk 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,∀i∈ωk
(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 ωk.
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 ∇q=a∇I.
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)=∑iϵωk((akIi+bk−pi)2+ϵak2)
in which
- ϵ is a regularization parameter penalizing large ak;
- ωk is a window centered at the pixel k.
And the cost function's solution is:
(5) ak=1|ω|∑iϵωkIipi−μkpk¯σk2+ϵ
(6) bk=pk¯−akμk
in which
- μk and σk2 are the mean and variance of I in ωk;
- |ω| is the number of pixels in ωk;
- p¯k=1|ω|∑iϵωkpi is the mean of p in ωk.
After obtaining the linear coefficients (ak,bk), the filtering output qi is provided by the following algorithm:
Algorithm
edit edit sourceBy definition, the algorithm can be written as:
Algorithm 1. Guided Filter
edit edit sourceinput: filtering input image p ,guidance image I ,window radius r ,regularization ϵ
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.∗meanp3.
a = covIp./(varI+ϵ) b = meanp−a.∗meanI4.
meana = fmean(a) meanb = fmean(b)5.
q = meana.∗I+meanbfmean is a mean filter with a wide variety of O(N) time methods.
Properties
edit edit sourceEdge-preserving filtering
edit edit sourceWhen 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 ϵ of the guided filter. Patches with variance much lower than the parameter ϵ will be smoothed, and those with variances much higher than ϵ will be preserved. The role of the range variance σr2 in the bilateral filter is similar to ϵ 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
edit edit sourceWhen 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
edit edit sourceDue 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
edit edit sourceSee also
edit edit sourceReferences
edit edit source- ^ He, Kaiming; Sun, Jian; Tang, Xiaoou (2013). "Guided Image Filtering". IEEE Transactions on Pattern Analysis and Machine Intelligence. 35 (6): 1397–1409. doi:10.1109/TPAMI.2012.213. PMID 23599054. Wikipedia revision 1258164511, retrieved 2026-11-18
- ^ Guided Image Filtering Wikipedia revision 1258164511, retrieved 2026-11-18
- ^ "Guided filtering of images - MATLAB imguidedfilter". Wikipedia revision 1258164511, retrieved 2026-11-18
- ^ "OpenCV: Filters". Wikipedia revision 1258164511, retrieved 2026-11-18
- ^ "FFmpeg Filters Documentation". Wikipedia revision 1258164511, retrieved 2026-11-18
Text derived from https://en.wikipedia.org/w/index.php?oldid=1258164511 under CC BY-SA 4.0; modifications have been made.