[77] | 1 | /* |
---|
| 2 | Copyright (C) 2006 Pedro Felzenszwalb |
---|
| 3 | |
---|
| 4 | This program is free software; you can redistribute it and/or modify |
---|
| 5 | it under the terms of the GNU General Public License as published by |
---|
| 6 | the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | (at your option) any later version. |
---|
| 8 | |
---|
| 9 | This program is distributed in the hope that it will be useful, |
---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | GNU General Public License for more details. |
---|
| 13 | |
---|
| 14 | You should have received a copy of the GNU General Public License |
---|
| 15 | along with this program; if not, write to the Free Software |
---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | /* some image utilities */ |
---|
| 20 | |
---|
| 21 | #ifndef IMUTIL_H |
---|
| 22 | #define IMUTIL_H |
---|
| 23 | |
---|
| 24 | #include "image.h" |
---|
| 25 | #include "misc.h" |
---|
| 26 | |
---|
| 27 | /* compute minimum and maximum value in an image */ |
---|
| 28 | /*template <class T> |
---|
| 29 | void min_max(image<T> *im, T *ret_min, T *ret_max) { |
---|
| 30 | int width = im->width(); |
---|
| 31 | int height = im->height(); |
---|
| 32 | |
---|
| 33 | T min = imRef(im, 0, 0); |
---|
| 34 | T max = imRef(im, 0, 0); |
---|
| 35 | for (int y = 0; y < height; y++) { |
---|
| 36 | for (int x = 0; x < width; x++) { |
---|
| 37 | T val = imRef(im, x, y); |
---|
| 38 | if (min > val) |
---|
| 39 | min = val; |
---|
| 40 | if (max < val) |
---|
| 41 | max = val; |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | *ret_min = min; |
---|
| 46 | *ret_max = max; |
---|
| 47 | } |
---|
| 48 | */ |
---|
| 49 | void min_max(imagef *im, float *ret_min, float *ret_max) { |
---|
| 50 | int width = im->w; |
---|
| 51 | int height = im->h; |
---|
| 52 | |
---|
| 53 | float min = imRef(im, 0, 0); |
---|
| 54 | float max = imRef(im, 0, 0); |
---|
| 55 | for (int y = 0; y < height; y++) { |
---|
| 56 | for (int x = 0; x < width; x++) { |
---|
| 57 | float val = imRef(im, x, y); |
---|
| 58 | if (min > val) |
---|
| 59 | min = val; |
---|
| 60 | if (max < val) |
---|
| 61 | max = val; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | *ret_min = min; |
---|
| 66 | *ret_max = max; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | /* threshold image */ |
---|
| 71 | /* |
---|
| 72 | template <class T> |
---|
| 73 | image<uchar> *threshold(image<T> *src, int t) { |
---|
| 74 | int width = src->width(); |
---|
| 75 | int height = src->height(); |
---|
| 76 | image<uchar> *dst = new image<uchar>(width, height); |
---|
| 77 | |
---|
| 78 | for (int y = 0; y < height; y++) { |
---|
| 79 | for (int x = 0; x < width; x++) { |
---|
| 80 | imRef(dst, x, y) = (imRef(src, x, y) >= t); |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | return dst; |
---|
| 85 | } |
---|
| 86 | */ |
---|
| 87 | /* |
---|
| 88 | image<uchar> *threshold(image<T> *src, int t) { |
---|
| 89 | int width = src->width(); |
---|
| 90 | int height = src->height(); |
---|
| 91 | image<uchar> *dst = new image<uchar>(width, height); |
---|
| 92 | |
---|
| 93 | for (int y = 0; y < height; y++) { |
---|
| 94 | for (int x = 0; x < width; x++) { |
---|
| 95 | imRef(dst, x, y) = (imRef(src, x, y) >= t); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | return dst; |
---|
| 100 | } |
---|
| 101 | */ |
---|
| 102 | #endif |
---|
| 103 | |
---|