Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Namespace Members | Data Fields | Globals

convolve.h

Go to the documentation of this file.
00001 /* convolution */
00002 
00003 #ifndef CONVOLVE_H
00004 #define CONVOLVE_H
00005 
00006 #include <vector>
00007 #include <algorithm>
00008 #include <cmath>
00009 #include "image.h"
00010 
00011 /* convolve src with mask.  dst is flipped! */
00012 static void convolve_even(image<float> *src, image<float> *dst, 
00013                           std::vector<float> &mask) {
00014   int width = src->width();
00015   int height = src->height();
00016   int len = mask.size();
00017 
00018   for (int y = 0; y < height; y++) {
00019     for (int x = 0; x < width; x++) {
00020       float sum = mask[0] * imRef(src, x, y);
00021       for (int i = 1; i < len; i++) {
00022         sum += mask[i] * 
00023           (imRef(src, std::max(x-i,0), y) + 
00024            imRef(src, std::min(x+i, width-1), y));
00025       }
00026       imRef(dst, y, x) = sum;
00027     }
00028   }
00029 }
00030 
00031 /* convolve src with mask.  dst is flipped! */
00032 static void convolve_odd(image<float> *src, image<float> *dst, 
00033                          std::vector<float> &mask) {
00034   int width = src->width();
00035   int height = src->height();
00036   int len = mask.size();
00037 
00038   for (int y = 0; y < height; y++) {
00039     for (int x = 0; x < width; x++) {
00040       float sum = mask[0] * imRef(src, x, y);
00041       for (int i = 1; i < len; i++) {
00042         sum += mask[i] * 
00043           (imRef(src, std::max(x-i,0), y) - 
00044            imRef(src, std::min(x+i, width-1), y));
00045       }
00046       imRef(dst, y, x) = sum;
00047     }
00048   }
00049 }
00050 
00051 #endif

Generated on Wed Oct 5 14:36:12 2005 for RobotFlow by  doxygen 1.4.4