Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #ifndef IMUTIL_H
00022 #define IMUTIL_H
00023 
00024 #include "image.h"
00025 #include "misc.h"
00026 
00027 
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 
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