背景
最近读到一篇关于Bilateral Filter(BF)的文章觉得写得甚好,以此总结下BF的原理与效果。基于BF有许多优秀的变种体,感兴趣的童鞋可以查看参考文献,本文只介绍基础的BF。为求更好的理解原文原意会放英文以供参考。
以下是双边滤波之所以受欢迎的一些特质:
- The formulation is simple - each pixel is replaced by an average of its neighbors. This aspect is important because it makes it easy to acquire intuition about its behavior, to adapt it to application-specific requirements, and to implement it.
- Fewer parameters - It depends only on two parameters that indicate the size and contrast of the features to preserve.
- It can be used in a non-iterative manner. This makes the parameters easy to set since their effect is not cumulative over several iterations.
- It can be computed at interactive speed even on large images thanks to efficient numerical schemes and even in real-time if graphics hardware is available.
Linear Filtering with Gaussian Blur (GB)
首先介绍一下Gaussian convolution(GC)也就是Gaussian Blur (GB),他和BF很接近但是不同的是没有保留边缘(not edge-preserving),其用于计算每一个位置的local average,相当于低通滤波(low-pass filtering)。公式如下
其中
为二维的高斯核(Gaussian kernel),来自于下式
为中心像素位置,
表示与他计算的另一个像素位置,
为
像素的像素值。
和
之间的空间距离使用·
来获取。
决定了该高斯分布的“宽度”,它的大小决定了以
为中心涵盖了多少的临近像素需要参与计算。以此计算方式图像
边缘就会被模糊掉了。如下图
Nonlinear Filtering with Bilateral Filter (BF)
BF其实也是基于权值平均的计算方式,不同的是他考虑到了图像边缘。公式如下
是一个归一化因子(normalization factor),如下
和
代表了对图片
进行滤波的程度。式3就表示了经过归一化后基于权值的平均结果。这里要注意两点,其一为
与
的像素值差距来衡量影响程度,差距愈大影响越小。Figure 4为使用BF的结果,第二三列的对比其实就展示了Figure 5在保留边缘(类似悬崖)上对平面进行的平滑模糊操作。这也就是我们会看到纹理的“重整”。但是私以为该result的参数设置不好使得人脸分块了(虽然分块内较为平滑),好的参数调整应该在保持平滑和边缘基础上避免该分块现象的出现,也就是过度要平滑。
不同参数下的效果
参考文献
A Gentle Introduction to Bilateral Filtering and its Applications