28 int col,
const int channel,
const int pad,
const double val)
32 if (row < 0 || col < 0 || row >= height || col >= width) {
35 im[col + width * (row + height * channel)] += val;
40 int col,
const int channel,
const int pad)
44 if (row < 0 || col < 0 || row >= height || col >= width) {
47 return im[col + width * (row + height * channel)];
63 col2im(
const double *data_col,
const int channels,
const int height,
64 const int width,
const int ksize,
const int stride,
const int pad,
67 const int height_col = (height + 2 * pad - ksize) / stride + 1;
68 const int width_col = (width + 2 * pad - ksize) / stride + 1;
69 const int channels_col = channels * ksize * ksize;
70 for (
int c = 0; c < channels_col; ++c) {
71 const int w_offset = c % ksize;
72 const int h_offset = (c / ksize) % ksize;
73 const int c_im = c / ksize / ksize;
74 for (
int h = 0; h < height_col; ++h) {
75 for (
int w = 0; w < width_col; ++w) {
76 const int im_row = h_offset + h * stride;
77 const int im_col = w_offset + w * stride;
78 const int col_index = (c * height_col + h) * width_col + w;
79 const double val = data_col[col_index];
100 im2col(
const double *data_im,
const int channels,
const int height,
101 const int width,
const int ksize,
const int stride,
const int pad,
104 const int height_col = (height + 2 * pad - ksize) / stride + 1;
105 const int width_col = (width + 2 * pad - ksize) / stride + 1;
106 const int channels_col = channels * ksize * ksize;
107 for (
int c = 0; c < channels_col; ++c) {
108 const int w_offset = c % ksize;
109 const int h_offset = (c / ksize) % ksize;
110 const int c_im = c / ksize / ksize;
111 for (
int h = 0; h < height_col; ++h) {
112 for (
int w = 0; w < width_col; ++w) {
113 const int im_row = h_offset + h * stride;
114 const int im_col = w_offset + w * stride;
115 const int col_index = (c * height_col + h) * width_col + w;
117 data_im, height, width, im_row, im_col, c_im, pad);
void im2col(const double *data_im, const int channels, const int height, const int width, const int ksize, const int stride, const int pad, double *data_col)
Transforms an image vector to a column vector.
static double im2col_get_pixel(const double *im, const int height, const int width, int row, int col, const int channel, const int pad)
static void col2im_add_pixel(double *im, const int height, const int width, int row, int col, const int channel, const int pad, const double val)
void col2im(const double *data_col, const int channels, const int height, const int width, const int ksize, const int stride, const int pad, double *data_im)
Transforms a column vector to an image vector.
Image handling functions.