Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Namespace Members | Data Fields | Globals

imutil.h

Go to the documentation of this file.
00001 /* some image utilities */
00002 
00003 #ifndef IMUTIL_H
00004 #define IMUTIL_H
00005 
00006 #include "image.h"
00007 #include "misc.h"
00008 
00009 /* compute minimum and maximum value in an image */
00010 template <class T>
00011 void min_max(image<T> *im, T *ret_min, T *ret_max) {
00012   int width = im->width();
00013   int height = im->height();
00014   
00015   T min = imRef(im, 0, 0);
00016   T max = imRef(im, 0, 0);
00017   for (int y = 0; y < height; y++) {
00018     for (int x = 0; x < width; x++) {
00019       T val = imRef(im, x, y);
00020       if (min > val)
00021         min = val;
00022       if (max < val)
00023         max = val;
00024     }
00025   }
00026 
00027   *ret_min = min;
00028   *ret_max = max;
00029 } 
00030 
00031 /* threshold image */
00032 template <class T>
00033 image<uchar> *threshold(image<T> *src, int t) {
00034   int width = src->width();
00035   int height = src->height();
00036   image<uchar> *dst = new image<uchar>(width, height);
00037   
00038   for (int y = 0; y < height; y++) {
00039     for (int x = 0; x < width; x++) {
00040       imRef(dst, x, y) = (imRef(src, x, y) >= t);
00041     }
00042   }
00043 
00044   return dst;
00045 }
00046 
00047 #endif
00048 

Generated on Wed Oct 5 14:36:12 2005 for RobotFlow by  doxygen 1.4.4