Apollo 11.0
自动驾驶开放平台
imutil.h
浏览该文件的文档.
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/*
18Copyright (C) 2006 Pedro Felzenszwalb
19This program is free software; you can redistribute it and/or modify
20it under the terms of the GNU General Public License as published by
21the Free Software Foundation; either version 2 of the License, or
22(at your option) any later version.
23This program is distributed in the hope that it will be useful,
24but WITHOUT ANY WARRANTY; without even the implied warranty of
25MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26GNU General Public License for more details.
27You should have received a copy of the GNU General Public License
28along with this program; if not, write to the Free Software
29Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30*/
31/* some image utilities */
32#pragma once
33
36
37namespace apollo {
38namespace perception {
39namespace lidar {
40
49template <class T>
50void min_max(Image<T> *im, T *ret_min, T *ret_max) {
51 int width = im->width();
52 int height = im->height();
53 T min = imRef(im, 0, 0);
54 T max = imRef(im, 0, 0);
55 for (int y = 0; y < height; y++) {
56 for (int x = 0; x < width; x++) {
57 T val = imRef(im, x, y);
58 if (min > val) {
59 min = val;
60 }
61 if (max < val) {
62 max = val;
63 }
64 }
65 }
66 *ret_min = min;
67 *ret_max = max;
68}
69
78template <class T>
80 int width = src->width();
81 int height = src->height();
82 Image<uchar> *dst = new Image<uchar>(width, height);
83 for (int y = 0; y < height; y++) {
84 for (int x = 0; x < width; x++) {
85 imRef(dst, x, y) = (imRef(src, x, y) >= t);
86 }
87 }
88 return dst;
89}
90} // namespace lidar
91} // namespace perception
92} // namespace apollo
int height() const
Get the height of an image
Definition image.h:73
int width() const
Get the width of an image
Definition image.h:64
#define imRef(im, x, y)
Definition image.h:88
void min_max(Image< T > *im, T *ret_min, T *ret_max)
Compute minimum and maximum value in an image
Definition imutil.h:50
Image< uchar > * threshold(Image< T > *src, int t)
Threshold image
Definition imutil.h:79
class register implement
Definition arena_queue.h:37