在学习cnn的过程中,对convolution的概念真的很是模糊,本来在学习图像处理的过程中,已对convolution有所了解,它与correlation是有不同的,因为convolution = correlation + filp over in both horizontal + vertical
但在CNN中,明明只是进行了correlation,但却称之为convolution,实在不解
下面, 将图像处理中的convolution重新整理记录
因为网络关于这部分的解释很多,这里直接借用其他 参考
“A convolution is done by multiplying a pixel‘s and its neighboring pixels color value by a matrix”, 这里的matrix就是convoluiton kernel (usually a small matrix of numbers)
这里假设图像是3*3,kernel也是3*3,实际计算中,有时为了使得卷积结果与原图像一致,会对原图像进行padding操作
原图像x:
0 | 0 | 0 | 0 | 0 |
0 | 1 | 2 | 3 | 0 |
0 | 4 | 5 | 6 | 0 |
0 | 7 | 8 | 9 | 0 |
0 | 0 | 0 | 0 | 0 |
x(0,0) | x(0,1) | x(0,2) | x(0,3) | x(0,4) |
x(1,0) | x(1,1) | x(1,2) | x(1,3) | x(1,4) |
x(2,0) | x(2,1) | x(2,2) | x(2,3) | x(2,4) |
x(3,0) | x(3,1) | x(3,2) | x(3,3) | x(3,4) |
x(4,0) | x(4,1) | x(4,2) | x(4,3) | x(4,4) |
卷积核h:
-1 | -2 | -1 |
0 | 0 | 0 |
1 | 2 | 1 |
h(1,1) | h(1,2) | h(1,3) |
h(2,1) | h(2,2) | h(2,3) |
h(3,1) | h(3,2) | h(3,3) |
具体的过程为:
将h先上下翻转,再左右翻转,然后,与x进行correlation运算
1 | 2 | 1 |
0 | 0 | 0 |
-1 | -2 | -1 |
h(3,3) | h(3,2) | h(3,1) |
h(2,3) | h(2,2) | h(2,1) |
h(1,1) | h(1,2) | h(1,1) |
输出结果y:3*3
x(0,0) | x(0,1) | x(0,2) | x(0,3) | x(0,4) |
x(1,0) | x(1,1) | x(1,2) | x(1,3) | x(1,4) |
x(2,0) | x(2,1) | x(2,2) | x(2,3) | x(2,4) |
x(3,0) | x(3,1) | x(3,2) | x(3,3) | x(3,4) |
x(4,0) | x(4,1) | x(4,2) | x(4,3) | x(4,4) |
依次覆盖,对应元素相乘
h(3,3) | h(3,2) | h(3,1) |
h(2,3) | h(2,2) | h(2,1) |
h(1,1) | h(1,2) | h(1,1) |
y(1,1) = h(3,3) *x(0,0) + h(3,2) *x(0,1) + h(3,1) *x(0,2) +
h(2,3) *x(1,0) + h(2,2) *x(1,1) + h(2,1) *x(1,2) +
h(1,3) *x(2,0) + h(1,2) *x(2,1) + h(1,1) *x(2,2)
其他元素类似
注:In image processing, a kernel, convolution matrix, or mask is a small matrix useful for blurring, sharpening, embossing, edge-detection, and more. This is accomplished by means of convolution between a kernel and an image.