Apollo  6.0
Open source self driving car software
imutil.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 /*
18 Copyright (C) 2006 Pedro Felzenszwalb
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License, or
22 (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 */
31 /* some image utilities */
32 #pragma once
33 
34 #include "modules/perception/lidar/detector/ncut_segmentation/common/graph_felzenszwalb/image.h"
35 #include "modules/perception/lidar/detector/ncut_segmentation/common/graph_felzenszwalb/misc.h"
36 
37 namespace apollo {
38 namespace perception {
39 namespace lidar {
40 /* compute minimum and maximum value in an image */
41 template <class T>
42 void min_max(Image<T> *im, T *ret_min, T *ret_max) {
43  int width = im->width();
44  int height = im->height();
45  T min = imRef(im, 0, 0);
46  T max = imRef(im, 0, 0);
47  for (int y = 0; y < height; y++) {
48  for (int x = 0; x < width; x++) {
49  T val = imRef(im, x, y);
50  if (min > val) {
51  min = val;
52  }
53  if (max < val) {
54  max = val;
55  }
56  }
57  }
58  *ret_min = min;
59  *ret_max = max;
60 }
61 /* threshold image */
62 template <class T>
64  int width = src->width();
65  int height = src->height();
66  Image<uchar> *dst = new Image<uchar>(width, height);
67  for (int y = 0; y < height; y++) {
68  for (int x = 0; x < width; x++) {
69  imRef(dst, x, y) = (imRef(src, x, y) >= t);
70  }
71  }
72  return dst;
73 }
74 } // namespace lidar
75 } // namespace perception
76 } // namespace apollo
int height() const
Definition: image.h:55
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int width() const
Definition: image.h:52
Definition: image.h:40
void min_max(Image< T > *im, T *ret_min, T *ret_max)
Definition: imutil.h:42
Image< uchar > * threshold(Image< T > *src, int t)
Definition: imutil.h:63
#define imRef(im, x, y)
Definition: image.h:68