3

I study convolution in image processing as it is a part of the curriculum, I understand the theory and the formula but I am confused about its implementation.

The formula is:


enter image description here


What I understand

The convolution kernel is flipped both horizontally and vertically then the values in the kernel are multiplied by the corresponding pixel values, the results are summed, divided by "row x column" to get the average, and then finally this result is the value of the pixel at the center of the kernel location.

Confusion in implementation

When I run the example convolution program from my course material and insert as input a 3x3 convolution kernel where:

1st row: (0, 1, 0)

2nd row: (0, 0, 0)

3rd row: (0, 0, 0)

The processed image is shifted down by one pixel, where I expected it to shift upwards by one pixel. This result indicates that no horizontal or vertical flipping is done before calculating (as if it is doing correlation).

I thought there might be a fault in the program so I looked around and found that Adobe Flex 3 and Gimp are doing this as well.

I don't understand, is there something that I missed to notice?

Appreciate any help or feedback.

4

2 回答 2

4

我猜您尝试的程序实现了相关性而不是卷积。

我已经使用该ImageFilter函数在 Mathematica 中尝试了您的过滤器,结果按预期向上移动:

在此处输入图像描述

结果:

在此处输入图像描述

我也在 Octave(一个开源的 Matlab 克隆)中尝试过它:

imfilter([1,1,1,1,1;
          2,2,2,2,2;
          3,3,3,3,3;
          4,4,4,4,4;
          5,5,5,5,5],
         [0,1,0;
          0,0,0;
          0,0,0],"conv")

(“conv”表示卷积 -imfilter的默认值是相关性)。结果:

   2   2   2   2   2
   3   3   3   3   3
   4   4   4   4   4
   5   5   5   5   5
   0   0   0   0   0

请注意,最后一行是不同的。这是因为不同的实现使用不同的填充(默认情况下)。Mathematica 对 使用常量填充ImageConvolve,对 没有填充ListConvolve。Octaveimfilter使用零填充。

另请注意(如 belisarius 所述)卷积的结果可以比源图像更小、相同或更大。(我在 Matlab 和 IPPI 文档中阅读了术语“有效”、“相同大小”和“完全”卷积,但我不确定这是否是标准术语)。这个想法是可以执行求和

  • 仅在内核完全位于图像内部的源图像像素上。在这种情况下,结果小于源图像。
  • 在每个源像素上。在这种情况下,结果与源图像具有相同的大小。这需要在边界处填充
  • 在内核的任何部分位于源图像内的每个像素上。在这种情况下,结果图像大于源图像。这也需要在边界处填充。
于 2011-09-17T22:04:26.913 回答
1

请注意:

在此处输入图像描述

结果是:

在此处输入图像描述

因此,“移动”不是真实的,因为尺寸会受到影响。

于 2011-09-17T21:11:31.973 回答