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

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

Added original make3d

File size: 1.6 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/* some image utilities */
20
21#ifndef IMUTIL_H
22#define IMUTIL_H
23
24#include "image.h"
25#include "misc.h"
26
27/* compute minimum and maximum value in an image */
28template <class T>
29void min_max(image<T> *im, T *ret_min, T *ret_max) {
30  int width = im->width();
31  int height = im->height();
32 
33  T min = imRef(im, 0, 0);
34  T max = imRef(im, 0, 0);
35  for (int y = 0; y < height; y++) {
36    for (int x = 0; x < width; x++) {
37      T val = imRef(im, x, y);
38      if (min > val)
39        min = val;
40      if (max < val)
41        max = val;
42    }
43  }
44
45  *ret_min = min;
46  *ret_max = max;
47} 
48
49/* threshold image */
50template <class T>
51image<uchar> *threshold(image<T> *src, int t) {
52  int width = src->width();
53  int height = src->height();
54  image<uchar> *dst = new image<uchar>(width, height);
55 
56  for (int y = 0; y < height; y++) {
57    for (int x = 0; x < width; x++) {
58      imRef(dst, x, y) = (imRef(src, x, y) >= t);
59    }
60  }
61
62  return dst;
63}
64
65#endif
66
Note: See TracBrowser for help on using the repository browser.