3.5 Smoothing (Lowpass) Spatial Filters


2019.5.11 更新高斯滤波核的推导二


Smooting spatial filters 也叫做 averaging spatial filters,通常用于减少图像亮度剧烈变化的部分(例如去噪,由于随机噪声常常是使图像发生亮度剧烈变化的成分)。平滑被用来去除图像中(小于滤波核部分)不相关的细节。

1. linear spatial filtering

As we discussed in Section 3.4 , linear spatial filtering consists of convolving an image with a filter kernel. Convolving a smoothing kernel with an image blurs the image, with the degree of blurring being determined by the size of the kernel and the values of its coefficients. In addition to being useful in countless applications of image processing, lowpass filters are fundamental, in the sense that other important filters, including sharpening (highpass), bandpass, and bandreject filters, can be derived from lowpass filters, as we will show in Section 3.7 .

将图像与平滑滤波器进行卷积会产生模糊效果,模糊的程度与卷积核的大小以及值有关。低通滤波器是最基础的,其他的滤波器如高通、带通、带阻滤波器都能由低通滤波器推导出来。

–> 两个重要的低通滤波器

(1) box filter kernels

box kernel 是最简单的可分离(即可分解为两个一维向量的外积, w = v 1 v 2 T w=v_1 v_2^T w=v1v2T)的低通滤波器,其系数值全为1,并伴随着一个归一化的常数(1/滤波器系数和)。归一化的作用:常量度区域的均值应等于滤波后的亮度值;滤波前后的像素和应相同。

This normalization, which we apply to all lowpass kernels, has two purposes. First, the average value of an area of constant intensity would equal that intensity in the filtered image, as it should. Second, normalizing the kernel in this way prevents introducing a bias during filtering; that is, the sum of the pixels in the original and filtered images will be the same。

低通滤波器对图像会产生整体模糊的效果,此外对于与滤波核大小差不多的区域影响较为严重。还有一个是滤波过程中的 zero padding 操作会产生暗边框效应。

(2) lowpass Gaussian filter kernels
高斯核的推导一

box filters 虽然操作简单且视觉效果显著,但具有局限性。例如其模糊效果具有方向性,偏爱于模糊垂直方向。针对于适合选用各项同性 (isotropic) 滤波器的应用:

In applications involving images with a high level of detail, or with strong geometrical components, the directionality of box filters often produces undesirable results.

常常选用 circularly symmetric的滤波器(also called isotropic, meaning their response is independent of orientation). 高斯核是唯一的可分离circularly symmetric kernel:
w ( s , t ) = G ( s , t ) = K e − s 2 + t 2 2 σ 2 w(s,t)=G(s,t)=Ke^{- \frac{s^2+t^2}{2\sigma^2}} w(s,t)=G(s,t)=Ke2σ2s2+t2

r = ( s 2 + t 2 ) 1 2 r=(s^2+t^2)^ \frac{1}{2} r=(s2+t2)21,上述式子可以转化为:
G ( r ) = K e − r 2 2 σ 2 G(r)=Ke^{-\frac{r^2}{2\sigma^2}} G(r)=Ke2σ2r2

变量 r r r表示从中心到函数任意一点上的距离。
在这里插入图片描述
对于高斯核也需要归一化处理。

(注意这里高斯函数的原点在核的中心,向下为x轴正方向,向右为y轴正方向。而图像的原点在左上角)
在这里插入图片描述

// C++生成高斯核
void getGaussianKernel(double **gaus, const int size, const double sigma) {
 const double PI = 4 * atan(1.0); // tan(pi/4)=1
 double sum = 0;
 int center = size / 2;
 for (int i = 0; i < size; i++) {
  for (int j = 0; j < size; j++) {
   gaus[i][j] = (1/(2*PI*sigma*sigma))*exp(-((i - center)*(i - center) + (j - center)*(j - center)) / (2 * sigma*sigma));
   sum += gaus[i][j];
  }
 }
 for (int i = 0; i < size; i++) {
  for (int j = 0; j < size; j++) {
   gaus[i][j] /= sum;
   cout << gaus[i][j] << " ";
  }
  cout << endl;
 }
 return;
}

C++中求高斯核:
G ( i , j ) = 1 2 π σ 2 e − ( i − c e n t e r ) 2 + ( j − c e n t e r ) 2 2 σ 2 G(i,j)=\frac{1}{2\pi \sigma^2} e^{-\frac{(i-center)^2+(j-center)^2}{2\sigma^2}} G(i,j)=2πσ21e2σ2(icenter)2+(jcenter)2

设核大小为 s i z e ∗ s i z e size*size sizesize, 则核中心的坐标为 c e n t e r = s i z e / 2 center=size/2 center=size/2。注意这里的下标都是从0开始,即 0 ≤ i ≤ s i z e − 1 0 \leq i \leq size-1 0isize1 0 ≤ j ≤ s i z e − 1 0 \leq j \leq size-1 0jsize1

需要注意的是,根据高斯函数的性质,我们知道距离均值超过 3 σ 3\sigma 3σ的点取值非常小可以忽略不计,因此若高斯核大小大于 6 σ 6\sigma 6σ,其滤波结果将不会有本质的区别,即再增大滤波核也不会有什么效果。实际处理时,我们常采用满足大于 6 σ 6\sigma 6σ的最小奇数作为高斯核的大小。即 s i z e = ⌈ 6 σ ⌉ size=\lceil6\sigma\rceil size=6σ

高斯函数的性质:两个高斯函数的乘积仍为高斯函数;两个高斯函数的卷积仍为高斯函数。因此多个高斯核的复合卷积操作可以转为用复合高斯核对图像进行滤波。

高斯核的推导二

以上是冈萨雷斯的书中给出的推导。下面以一种更易于理解的方式来说,参考这儿

我们知道,需要根据高斯函数获得高斯滤波核。
我们以核中心为原点,因此高斯函数的均值为0。根据高斯函数性质,离核中心越远,滤波核对应的值越小,可以看下面的二维正态分布的函数图像。
在这里插入图片描述
二维高斯函数为:(注意我们使用均值为0)
G ( x , y ) = 1 2 π σ 2 e − x 2 + y 2 2 σ 2 G(x,y)=\frac{1}{2\pi\sigma^2}e^{-\frac{x^2+y^2}{2\sigma^2}} G(x,y)=2πσ21e2σ2x2+y2

我们令高斯核中心点的坐标为(0,0),则其他点对应的坐标为:
在这里插入图片描述
求高斯核的公式可以统一为:
G ( i , j ) = 1 2 π σ 2 e − ( i − c e n t e r ) 2 + ( j − c e n t e r ) 2 2 σ 2 G(i,j)=\frac{1}{2\pi\sigma^2}e^{-\frac{(i-center)^2+(j-center)^2}{2\sigma^2}} G(i,j)=2πσ21e2σ2(icenter)2+(jcenter)2

(i,j)表示像素位置(i,j),center 表示滤波核的中心位置为(center,center)。这样无论坐标从0开始(例如C++)还是从1开始(例如MATLAB),都可以按上述式子计算,只要计算出对应的滤波核的中心位置坐标(center,center)

–> Comparison of Gaussian and box filter smoothing characteristics

比较一下高斯滤波和均匀滤波的一些特点。
在这里插入图片描述
如图所示,中间的图是均匀滤波的效果,可以看见,the box filter产生线性平滑的效果,即仍存在较为明显的边缘,当不需要比较平滑的边缘时可以采用这种滤波器;而the Gaussian filter产生更加平滑的结果,如果需要均匀的平滑效果通常采用这类滤波器。

–> image padding

除了zero padding以外,再介绍两种边界扩充的方法,尝试将图像的特征扩展到边界之外。
(1) mirror padding (symmetric padding)
根据边界进行镜面反射来扩充边界;当边界附近区域包含图像细节时比较有用,
(2) replicate padding
将边界外的值设置为距离最近的边界值;常用于图像边界附近区域是常量时。

–> shading correction using lowpass filtering

可以用低通滤波估计阴影模型。对原图像进行低通滤波(例如使用高斯核,注意比核小的细节将被平滑)获得阴影模型,然后用原图像除以阴影模型获得阴影校正的结果。(通常阴影以乘法作用于图像,因此可通过分解获得校正后的图像。)

2. nonlinear filters

order-statistic filters (统计排序滤波器) 是一类非线性滤波器,例如中值滤波,即用邻域像素值排序的中值作为滤波响应。

(1) 中值滤波(去除椒盐噪声)

Median filters provide excellent noise reduction capabilities for certain types of random noise, with considerably less blurring than linear smoothing filters of similar size. Median filters are particularly effective in the presence of impulse noise (sometimes called salt-and-pepper noise, when it manisfests itself as white and black dots superimposed on an image).

中值滤波能够有效地去除椒盐噪声。且相对于相似大小地线性滤波器,其模糊程度要小很多。 中值滤波的主要作用使某一点的像素值更接近其邻域的像素值。对于孤立点而言,其像素值比邻域像素值亮或者暗,而均值滤波将会迫使该点的像素值更接近邻域像素,对孤立噪声点的去除较为有效。(因此能有效处理椒盐噪声,同时保留图像的细节。而低通滤波器例如高斯滤波器往往会产生更加模糊的效果。)

(2) max filter (最大值滤波)

For example, using the 100th percentile results in the so-called max filter, which is useful for finding the brightest points in an image or for eroding dark areas adjacent to light regions.

对于寻找最亮点以及腐蚀靠近亮区域的暗区域很有用。

(3) min filter (最小值滤波)

参考文献:

  1. 数字图像处理3.6节,冈萨雷斯
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值