source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/Superpixels/SourceCode/segment/convolve.h @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.9 KB
Line 
1/*
2Copyright (C) 2006 Pedro Felzenszwalb
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17*/
18
19/* convolution */
20
21#ifndef CONVOLVE_H
22#define CONVOLVE_H
23
24#include <vector>
25#include <algorithm>
26#include <cmath>
27#include "image.h"
28
29/* convolve src with mask.  dst is flipped! */
30static void convolve_even(image<float> *src, image<float> *dst, 
31                          std::vector<float> &mask) {
32  int width = src->width();
33  int height = src->height();
34  int len = mask.size();
35
36  for (int y = 0; y < height; y++) {
37    for (int x = 0; x < width; x++) {
38      float sum = mask[0] * imRef(src, x, y);
39      for (int i = 1; i < len; i++) {
40        sum += mask[i] * 
41          (imRef(src, std::max(x-i,0), y) + 
42           imRef(src, std::min(x+i, width-1), y));
43      }
44      imRef(dst, y, x) = sum;
45    }
46  }
47}
48
49/* convolve src with mask.  dst is flipped! */
50static void convolve_odd(image<float> *src, image<float> *dst, 
51                         std::vector<float> &mask) {
52  int width = src->width();
53  int height = src->height();
54  int len = mask.size();
55
56  for (int y = 0; y < height; y++) {
57    for (int x = 0; x < width; x++) {
58      float sum = mask[0] * imRef(src, x, y);
59      for (int i = 1; i < len; i++) {
60        sum += mask[i] * 
61          (imRef(src, std::max(x-i,0), y) - 
62           imRef(src, std::min(x+i, width-1), y));
63      }
64      imRef(dst, y, x) = sum;
65    }
66  }
67}
68
69#endif
Note: See TracBrowser for help on using the repository browser.