Main Content

什么是空间域中的图像滤波?

滤波是一种用于修正或增强图像的技术。例如,您可以对图像进行滤波以强调某些特征或删除其他特征。用滤波实现的图像处理运算包括平滑、锐化和边缘增强。

滤波是一种邻域运算,它通过对对应输入像素邻域中的像素值应用某种算法来确定输出图像中任何给定像素的值。像素的领域是一组像素,由它们相对于该像素的位置来确定。(有关邻域运算的一般性讨论,请参阅Neighborhood or Block Processing: An Overview。)线性滤波是一种滤波,其中输出像素的值是输入像素邻域中像素值的线性组合。

卷积

图像的线性滤波是通过称为卷积的运算完成的。卷积是一种邻域运算,其中每个输出像素是相邻输入像素的加权和。权重矩阵称为卷积核,也称为滤波器。卷积核是旋转了 180 度的相关性核。

例如,假设图像是

A = [17  24   1   8  15
     23   5   7  14  16
      4   6  13  20  22
     10  12  19  21   3
     11  18  25   2   9]

相关性核是

h = [8   1   6
     3   5   7
     4   9   2]

您将使用以下步骤计算位置 (2, 4) 处的输出像素:

  1. 将相关性核关于其中心元素旋转 180 度以创建卷积核。

  2. 滑动卷积核的中心元素,将其叠加在 A 的 (2, 4) 元素之上。

  3. 将旋转后的卷积核中的每个权重乘以下方的 A 的像素。

  4. 对步骤 3 中得到的各个乘积求和。

因此,(2, 4) 输出像素为

计算如下图所示。

计算卷积的 (2, 4) 输出

A grid of pixels displaying the pixel values. The 3-by-3 pixel neighborhood around the (2, 4) element is highlighted in gray, indicating the position of the convolution kernel. For pixels in the neighborhood, the grid also displays the weights of the convolution kernel, which is equal to the rotated matrix h.

相关性

称为相关性的运算与卷积密切相关。在相关性中,输出像素的值也计算为相邻像素的加权和。不同之处在于权重矩阵(在本例中称为相关性核)在计算过程中不旋转。Image Processing Toolbox™ 滤波器设计函数返回相关性核。

下图显示如何计算 A 的相关性的 (2, 4) 输出像素,假设 h 是相关性核而不是卷积核,使用以下步骤:

  1. 滑动相关性核的中心元素,将其叠加到 A 的 (2, 4) 元素的上方。

  2. 将相关性核中的每个权重乘以下方 A 的像素。

  3. 对各乘积求和。

基于相关性的 (2, 4) 输出像素为

计算相关性的 (2, 4) 输出

A grid of pixels displaying the pixel values. The 3-by-3 pixel neighborhood around the (2, 4) element is highlighted in gray, indicating the position of the convolution kernel. For pixels in the neighborhood, the grid also displays the weights of the convolution kernel, which is equal to the matrix h defined above.

另请参阅

| |

相关主题