forked from dilin993/Conv2D_fixedp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conv.cpp
32 lines (27 loc) · 982 Bytes
/
conv.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "conv.h"
void conv2Dfixp(data_t in[IMGW*IMGH],data_t out[IMGW*IMGH],data_t kernel[K*K])
{
const short kCenterX = K / 2;
const short kCenterY = K / 2;
for(short i=0; i < IMGH; ++i) // rows
{
for(short j=0; j < IMGW; ++j) // columns
{
for(short m=0; m < K; ++m) // kernel rows
{
//short mm = K - 1 - m; // row index of flipped kernel
for(short n=0; n < K; ++n) // kernel columns
{
//short nn = K - 1 - n; // column index of flipped kernel
// index of input signal, used for checking boundary
short ii = i + (m - kCenterY);
short jj = j + (n - kCenterX);
//
// // ignore input samples which are out of bound
if( ii >= 0 && ii < IMGH && jj >= 0 && jj < IMGW )
out[i*IMGW+j] += in[ii*IMGW+jj] * kernel[K*m+n];
}
}
}
}
}