im2col.c
Go to the documentation of this file.
00001 #include "im2col.h"
00002 #include <stdio.h>
00003 float im2col_get_pixel(float *im, int height, int width, int channels,
00004                         int row, int col, int channel, int pad)
00005 {
00006     row -= pad;
00007     col -= pad;
00008 
00009     if (row < 0 || col < 0 ||
00010         row >= height || col >= width) return 0;
00011     return im[col + width*(row + height*channel)];
00012 }
00013 
00014 //From Berkeley Vision's Caffe!
00015 //https://github.com/BVLC/caffe/blob/master/LICENSE
00016 void im2col_cpu(float* data_im,
00017      int channels,  int height,  int width,
00018      int ksize,  int stride, int pad, float* data_col) 
00019 {
00020     int c,h,w;
00021     int height_col = (height + 2*pad - ksize) / stride + 1;
00022     int width_col = (width + 2*pad - ksize) / stride + 1;
00023 
00024     int channels_col = channels * ksize * ksize;
00025     for (c = 0; c < channels_col; ++c) {
00026         int w_offset = c % ksize;
00027         int h_offset = (c / ksize) % ksize;
00028         int c_im = c / ksize / ksize;
00029         for (h = 0; h < height_col; ++h) {
00030             for (w = 0; w < width_col; ++w) {
00031                 int im_row = h_offset + h * stride;
00032                 int im_col = w_offset + w * stride;
00033                 int col_index = (c * height_col + h) * width_col + w;
00034                 data_col[col_index] = im2col_get_pixel(data_im, height, width, channels,
00035                         im_row, im_col, c_im, pad);
00036             }
00037         }
00038     }
00039 }
00040 


rail_object_detector
Author(s):
autogenerated on Sat Jun 8 2019 20:26:30