convolve.h
Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2006 Pedro Felzenszwalb
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 */
00018 
00019 /* convolution */
00020 
00021 #ifndef CONVOLVE_H
00022 #define CONVOLVE_H
00023 
00024 #include <vector>
00025 #include <algorithm>
00026 #include <cmath>
00027 #include "image.h"
00028 
00029 /* convolve src with mask.  dst is flipped! */
00030 static void convolve_even(image<float> *src, image<float> *dst, 
00031                           std::vector<float> &mask) {
00032   int width = src->width();
00033   int height = src->height();
00034   int len = mask.size();
00035 
00036   for (int y = 0; y < height; y++) {
00037     for (int x = 0; x < width; x++) {
00038       float sum = mask[0] * imRef(src, x, y);
00039       for (int i = 1; i < len; i++) {
00040         sum += mask[i] * 
00041           (imRef(src, std::max(x-i,0), y) + 
00042            imRef(src, std::min(x+i, width-1), y));
00043       }
00044       imRef(dst, y, x) = sum;
00045     }
00046   }
00047 }
00048 
00049 /* convolve src with mask.  dst is flipped! */
00050 static void convolve_odd(image<float> *src, image<float> *dst, 
00051                          std::vector<float> &mask) {
00052   int width = src->width();
00053   int height = src->height();
00054   int len = mask.size();
00055 
00056   for (int y = 0; y < height; y++) {
00057     for (int x = 0; x < width; x++) {
00058       float sum = mask[0] * imRef(src, x, y);
00059       for (int i = 1; i < len; i++) {
00060         sum += mask[i] * 
00061           (imRef(src, std::max(x-i,0), y) - 
00062            imRef(src, std::min(x+i, width-1), y));
00063       }
00064       imRef(dst, y, x) = sum;
00065     }
00066   }
00067 }
00068 
00069 #endif


iri_leaf_fitting
Author(s): Sergi Foix
autogenerated on Fri Dec 6 2013 20:28:17