darknet  v3
im2col.c
Go to the documentation of this file.
1 #include "im2col.h"
2 #include <stdio.h>
3 float im2col_get_pixel(float *im, int height, int width, int channels,
4  int row, int col, int channel, int pad)
5 {
6  row -= pad;
7  col -= pad;
8 
9  if (row < 0 || col < 0 ||
10  row >= height || col >= width) return 0;
11  return im[col + width*(row + height*channel)];
12 }
13 
14 //From Berkeley Vision's Caffe!
15 //https://github.com/BVLC/caffe/blob/master/LICENSE
16 void im2col_cpu(float* data_im,
17  int channels, int height, int width,
18  int ksize, int stride, int pad, float* data_col)
19 {
20  int c,h,w;
21  int height_col = (height + 2*pad - ksize) / stride + 1;
22  int width_col = (width + 2*pad - ksize) / stride + 1;
23 
24  int channels_col = channels * ksize * ksize;
25  for (c = 0; c < channels_col; ++c) {
26  int w_offset = c % ksize;
27  int h_offset = (c / ksize) % ksize;
28  int c_im = c / ksize / ksize;
29  for (h = 0; h < height_col; ++h) {
30  for (w = 0; w < width_col; ++w) {
31  int im_row = h_offset + h * stride;
32  int im_col = w_offset + w * stride;
33  int col_index = (c * height_col + h) * width_col + w;
34  data_col[col_index] = im2col_get_pixel(data_im, height, width, channels,
35  im_row, im_col, c_im, pad);
36  }
37  }
38  }
39 }
40 
float im2col_get_pixel(float *im, int height, int width, int channels, int row, int col, int channel, int pad)
Definition: im2col.c:3
void im2col_cpu(float *data_im, int channels, int height, int width, int ksize, int stride, int pad, float *data_col)
Definition: im2col.c:16