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 #ifndef IMUTIL_H
00022 #define IMUTIL_H
00023 
00024 #include "image.h"
00025 #include "misc.h"
00026 
00027 /* compute minimum and maximum value in an image */
00028 template <class T>
00029 void min_max(image<T> *im, T *ret_min, T *ret_max) {
00030   int width = im->width();
00031   int height = im->height();
00032   
00033   T min = imRef(im, 0, 0);
00034   T max = imRef(im, 0, 0);
00035   for (int y = 0; y < height; y++) {
00036     for (int x = 0; x < width; x++) {
00037       T val = imRef(im, x, y);
00038       if (min > val)
00039         min = val;
00040       if (max < val)
00041         max = val;
00042     }
00043   }
00044 
00045   *ret_min = min;
00046   *ret_max = max;
00047 } 
00048 
00049 /* threshold image */
00050 template <class T>
00051 image<uchar> *threshold(image<T> *src, int t) {
00052   int width = src->width();
00053   int height = src->height();
00054   image<uchar> *dst = new image<uchar>(width, height);
00055   
00056   for (int y = 0; y < height; y++) {
00057     for (int x = 0; x < width; x++) {
00058       imRef(dst, x, y) = (imRef(src, x, y) >= t);
00059     }
00060   }
00061 
00062   return dst;
00063 }
00064 
00065 #endif
00066 


iri_leaf_segmentation
Author(s): Sergi Foix
autogenerated on Fri Dec 6 2013 20:27:24