imutil.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2006 Pedro Felzenszwalb
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 /* some image utilities */
20 
21 #pragma once
22 
23 #include "image.h"
24 #include "misc.h"
25 
26 namespace distance_transform
27 {
28 
29  /* compute minimum and maximum value in an image */
30  template <class T>
31  void min_max(image<T> *im, T *ret_min, T *ret_max) {
32  int width = im->width();
33  int height = im->height();
34 
35  T min = imRef(im, 0, 0);
36  T max = imRef(im, 0, 0);
37  for (int y = 0; y < height; y++) {
38  for (int x = 0; x < width; x++) {
39  T val = imRef(im, x, y);
40  if (min > val)
41  min = val;
42  if (max < val)
43  max = val;
44  }
45  }
46 
47  *ret_min = min;
48  *ret_max = max;
49  }
50 
51  /* threshold image */
52  template <class T>
54  int width = src->width();
55  int height = src->height();
56  image<uchar> *dst = new image<uchar>(width, height);
57 
58  for (int y = 0; y < height; y++) {
59  for (int x = 0; x < width; x++) {
60  imRef(dst, x, y) = (imRef(src, x, y) >= t);
61  }
62  }
63 
64  return dst;
65  }
66 
67 } // namespace
void min_max(image< T > *im, T *ret_min, T *ret_max)
Definition: imutil.h:31
int width() const
Definition: image.h:44
TFSIMD_FORCE_INLINE const tfScalar & y() const
#define imRef(im, x, y)
Definition: image.h:60
int height() const
Definition: image.h:47
TFSIMD_FORCE_INLINE const tfScalar & x() const
image< uchar > * threshold(image< T > *src, int t)
Definition: imutil.h:53
int min(int a, int b)


grid_map_sdf
Author(s): Takahiro Miki , Péter Fankhauser
autogenerated on Tue Jun 1 2021 02:13:49