Gaussian.cc
Go to the documentation of this file.00001 #include "Gaussian.h"
00002 #include <iostream>
00003
00004 namespace AprilTags {
00005
00006 bool Gaussian::warned = false;
00007
00008 std::vector<float> Gaussian::makeGaussianFilter(float sigma, int n) {
00009 std::vector<float> f(n,0.0f);
00010
00011 if (sigma == 0) {
00012 for (int i = 0; i < n; i++)
00013 f[i] = 0;
00014 f[n/2] = 1;
00015 return f;
00016 }
00017
00018 float const variance = 2*sigma*sigma;
00019 float sum = 0;
00020 for (int i = 0; i < n; i++) {
00021 int j = i - n/2;
00022 f[i] = std::exp(-j*j/variance);
00023 sum += f[i];
00024 }
00025
00026
00027 for (int i = 0; i < n; i++)
00028 f[i] /= sum;
00029
00030 return f;
00031 }
00032
00033 void Gaussian::convolveSymmetricCentered(const std::vector<float>& a, unsigned int aoff, unsigned int alen,
00034 const std::vector<float>& f, std::vector<float>& r, unsigned int roff) {
00035 if ((f.size()&1)== 0 && !warned) {
00036 std::cout<<"convolveSymmetricCentered Warning: filter is not odd length\n";
00037 warned = true;
00038 }
00039
00040 for (size_t i = f.size()/2; i < f.size(); i++) {
00041 float acc = 0;
00042 for (size_t j = 0; j < f.size(); j++) {
00043 if ((aoff + i) < j || (aoff + i) >= (alen + j))
00044 acc += a[aoff] * f[j];
00045 else
00046 acc += a[aoff + i - j] * f[j];
00047 }
00048 r[roff + i - f.size()/2] = acc;
00049 }
00050
00051 for (size_t i = f.size(); i < alen; i++) {
00052 float acc = 0;
00053 for (unsigned int j = 0; j < f.size(); j++) {
00054 acc += a[aoff + i - j] * f[j];
00055 }
00056 r[roff + i - f.size()/2] = acc;
00057 }
00058
00059 for (size_t i = alen; i < alen + f.size()/2; i++) {
00060 float acc = 0;
00061 for (size_t j = 0; j < f.size(); j++) {
00062 if ((aoff + i) >= (alen + j) || (aoff + i) < j)
00063 acc += a[aoff + alen - 1] * f[j];
00064 else
00065 acc += a[aoff + i - j] * f[j];
00066 }
00067 r[roff + i - f.size()/2] = acc;
00068 }
00069 }
00070
00071 }