44 const num *src,
long src_stride,
long N,
long r)
49 assert(dest && src && dest != src && N > 0 && r >= 0);
53 for (n = -r; n <= r; ++n)
54 accum += src[src_stride *
extension(N, n)];
59 for (n = 1; n < N; ++n)
62 accum += src[src_stride *
extension(N, n + r)]
63 - src[src_stride *
extension(N, n - r - 1)];
64 dest[dest_stride * n] = accum;
106 long N,
long stride,
num sigma,
int K)
112 } dest, buffer, cur, next;
117 assert(dest_data && buffer_data && src && dest_data != buffer_data
118 && N > 0 && sigma > 0 && K > 0);
121 r = (long)(0.5 * sqrt((12.0 * sigma * sigma) / K + 1.0));
122 scale = (
num)(1.0 / pow(2*r + 1, K));
124 dest.data = dest_data;
125 dest.stride = stride;
126 buffer.data = buffer_data;
127 buffer.stride = (buffer_data == src) ? stride : 1;
141 if (buffer_data == src || (dest_data != src && K % 2 == 1))
147 box_filter(next.data, next.stride, src, stride, N, r);
151 for (step = 1; step < K; ++step)
154 next = (cur.data == buffer_data) ? dest : buffer;
155 box_filter(next.data, next.stride, cur.data, cur.stride, N, r);
159 if (next.data != dest_data)
163 for (n = i = 0; n < N; ++n, i += stride)
164 dest_data[i] = buffer_data[n] * scale;
168 long i, i_end = stride * N;
170 for (i = 0; i < i_end; i += stride)
171 dest_data[i] *= scale;
196 int width,
int height,
int num_channels,
num sigma,
int K)
198 const long num_pixels = ((long)width) * ((long)height);
201 assert(dest && buffer && src && dest != buffer
202 && num_pixels > 0 && sigma > 0 && K > 0);
205 for (channel = 0; channel < num_channels; ++channel)
208 const num *src_y = src;
211 for (y = 0; y < height; ++y)
220 for (x = 0; x < width; ++x)
222 height, width, sigma, K);