您的位置:首页 > 其它

2D image convolution(二维图像卷积)

2016-04-01 10:33 225 查看
在学习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:

具体数值:

00000
01230
04560
07890
00000
表示为x的元素形式

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
000
121
表示为h的元素的形式:

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进行卷积操作的具体的过程为:

(1)将h先上下翻转,再左右翻转

二次翻转后的h的具体数值:

121
000
-1-2-1
二次翻转后的h的以各元素的形式表示:

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)
(2)然后,将二次翻转后的h与x进行correlation运算,即 二次翻转后的h依次覆盖x,同时对应元素相乘并相加

矩阵x:

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:

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)
(3)输出结果为矩阵y,大小为3*3,y(1,1)的数值如下(即二次翻转后的h覆盖在x的第一个位置所得的值)

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: