602
社区成员
发帖
与我相关
我的任务
分享
template <typename Out, typename In>
static void filter1D(Out& output, In& data, std::vector<float>& filter,
int height, int width, int channel, bool filterRows)
{
for (int j = 0; j < width; ++j)
{
for (int i = 0; i < height; ++i)
{
float s = 0.0f;
for (int f = 0; f < filter.size(); ++f)
{
int offs = f - filter.size() / 2;
int ioff = filterRows ? (std::min)((int)height - 1, (std::max)(0, i + offs)) : i;
int joff = filterRows ? j : (std::min)((int)width - 1, (std::max)(0, j + offs));
// conv2 style boundary handling
//int ioff = filterRows ? i + offs : i;
//int joff = filterRows ? j : j + offs;
//if (ioff >= height || ioff < 0 || joff >= width || joff < 0) continue;
s += data[height*width*channel + height*joff + ioff] * filter[f];
}
output[height*width*channel + height*j + i] = s;
}
}
std::vector<float> pass1(height * width * nchannels);
std::vector<float> gradIm(height * width * nchannels);
for (int c = 0; c < nchannels; ++c)
{
for (int histIdx = 0; histIdx < nHists / 2; ++histIdx)
{
switch (histIdx)
{
case 0:
// Y dir
filter1D(pass1, image, gaussianDeriv, height, width, c, true);
filter1D(gradIm, pass1, gaussian, height, width, c, false);