imutil.h
Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2006 Pedro Felzenszwalb
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 */
00018 
00019 /* some image utilities */
00020 
00021 #pragma once
00022 
00023 #include "image.h"
00024 #include "misc.h"
00025 
00026 namespace distance_transform
00027 {
00028 
00029   /* compute minimum and maximum value in an image */
00030   template <class T>
00031   void min_max(image<T> *im, T *ret_min, T *ret_max) {
00032     int width = im->width();
00033     int height = im->height();
00034     
00035     T min = imRef(im, 0, 0);
00036     T max = imRef(im, 0, 0);
00037     for (int y = 0; y < height; y++) {
00038       for (int x = 0; x < width; x++) {
00039         T val = imRef(im, x, y);
00040         if (min > val)
00041     min = val;
00042         if (max < val)
00043     max = val;
00044       }
00045     }
00046 
00047     *ret_min = min;
00048     *ret_max = max;
00049   } 
00050 
00051   /* threshold image */
00052   template <class T>
00053   image<uchar> *threshold(image<T> *src, int t) {
00054     int width = src->width();
00055     int height = src->height();
00056     image<uchar> *dst = new image<uchar>(width, height);
00057     
00058     for (int y = 0; y < height; y++) {
00059       for (int x = 0; x < width; x++) {
00060         imRef(dst, x, y) = (imRef(src, x, y) >= t);
00061       }
00062     }
00063 
00064     return dst;
00065   }
00066 
00067 } // namespace


grid_map_sdf
Author(s): Takahiro Miki , Péter Fankhauser
autogenerated on Tue Jul 9 2019 05:06:48