34 static void normalize(std::vector<float> &mask) {
35 int len = mask.size();
37 for (
int i = 1; i < len; i++) {
40 sum = 2*sum + fabs(mask[0]);
41 for (
int i = 0; i < len; i++) {
47 #define MAKE_FILTER(name, fun) \
48 static std::vector<float> make_ ## name (float sigma) { \
49 sigma = std::max(sigma, 0.01F); \
50 int len = (int)ceil(sigma * WIDTH) + 1; \
51 std::vector<float> mask(len); \
52 for (int i = 0; i < len; i++) { \
58 MAKE_FILTER(fgauss, exp(-0.5*square(i/sigma)));
61 static image<float> *smooth(image<float> *src,
float sigma) {
62 std::vector<float> mask = make_fgauss(sigma);
65 image<float> *tmp =
new image<float>(src->height(), src->width(),
false);
66 image<float> *dst =
new image<float>(src->width(), src->height(),
false);
67 convolve_even(src, tmp, mask);
68 convolve_even(tmp, dst, mask);
75 image<float> *smooth(image<uchar> *src,
float sigma) {
76 image<float> *tmp = imageUCHARtoFLOAT(src);
77 image<float> *dst = smooth(tmp, sigma);
83 static image<float> *laplacian(image<float> *src) {
84 int width = src->width();
85 int height = src->height();
86 image<float> *dst =
new image<float>(width, height);
88 for (
int y = 1; y < height-1; y++) {
89 for (
int x = 1; x < width-1; x++) {
90 float d2x = imRef(src, x-1, y) + imRef(src, x+1, y) -
92 float d2y = imRef(src, x, y-1) + imRef(src, x, y+1) -
94 imRef(dst, x, y) = d2x + d2y;