Example of 2D Convolution

此篇帖子均来自:

http://www.songho.ca/dsp/convolution/convolution2d_example.html

Example of 2D Convolution

Here is a simple example of convolution of 3x3 input signal and impulse response (kernel) in 2D spatial. The definition of 2D convolution and the method how to convolve in 2D are explained here.

In general, the size of output signal is getting bigger than input signal, but we compute only same area as input has been defined. Because we forced to pad zeros where inputs are not defined, such as x[-1,-1], the results around the edge cannot be accurate. Plus, the size of output is fixed as same as input size in most image processing.

下面是2D空间中的3x3输入信号和脉冲响应(内核)的卷积的简单示例。二维卷积的定义和如何在2D中进行卷积的方法在这里解释

一般来说,输出信号的大小比输入信号大,但是我们只计算与输入相同的面积。因为我们不得不填充输入未定义的零点,比如x [-1,-1],所以边缘的结果是不准确的。另外,在大多数图像处理中,输出的大小与输入大小相同。


x[m,n] 
Input
h[m,n] 
Kernel
y[m,n] 
Output

Notice that the origin of impulse response is always centered. (h[0,0] is located at the center sample of kernel, not the first element.)

Let's start calculate each sample of the output one by one. 
First, flip the kernel, which is the shaded box, in both horizontal and vertical direction. Then, move it over the input array. If the kernel is centered (aligned) exactly at the sample that we are interested in, multiply the kernel data by the overlapped input data. 
The accumulation (adding these 9 multiplications) is the last thing to do to find out the output value. 

Note that the matrices are referenced here as [column, row], not [row, column]. M is horizontal (column) direction and N is vertical (row) direction.

请注意,脉冲响应的起源始终居中。h [0,0]位于内核的中心示例,而不是第一个元素)。

我们开始逐个计算输出的每个样本。 
首先,在水平和垂直方向翻转内核,即阴影框。然后,将其移到输入数组上。如果内核正好在我们感兴趣的样本中居中(对齐),则将内核数据乘以重叠的输入数据。 
积累(加上这9个乘法)是找出输出值的最后一件事。 

请注意,矩阵在这里被称为[列,行],而不是[行,列]。M是水平(列)方向,N是垂直(行)方向。


y[0,0]
y[0,0]
 
y[1,0]
y[1,0]
 
y[2,0]
y[2,0]
 
y[0,1]
y[0,1]
 
y[1,1]
y[1,1]
 
y[2,1]
y[2,1]
 
y[0,2]
y[0,2]
 
y[1,2]
y[1,2]
 
y[2,2]
y[2,2]
 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值