2 * folded-ctf is an implementation of the folded hierarchy of
3 * classifiers for object detection, developed by Francois Fleuret
6 * Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
7 * Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 * This file is part of folded-ctf.
11 * folded-ctf is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 3 as
13 * published by the Free Software Foundation.
15 * folded-ctf is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with folded-ctf. If not, see <http://www.gnu.org/licenses/>.
27 A RichImage is an Image with all the necessary pre-computation to
28 compute the feature responses: Edge detection and local variance
29 thresholding at multiple scale, with integral images. The heavy
30 machinery and ugly coding style is motivated by performance.
38 #include "rgb_image.h"
42 class RichImage : public Image {
44 static const int _image_size_min = 8;
48 int *_width_at_scale, *_height_at_scale;
50 unsigned int *_edge_map;
52 unsigned int **_line_edge_map;
53 unsigned int ***_tag_edge_map;
54 unsigned int ****_scale_edge_map;
58 void compute_one_scale_edge_maps(int width, int height,
59 unsigned int ***scale_edge_map,
60 unsigned char *pixel_map,
61 unsigned int *sum_pixel_map,
62 unsigned int *sum_sq_pixel_map);
66 // We have 8 edge orientations
67 static const int nb_edge_tags = 8;
68 static const int first_edge_tag = 0;
70 // The variance tag is 1 if the variance of the gray levels in the
71 // 16x16 square is greater than 10
72 static const int variance_tag = 8;
74 // We quantify the grayscales into 8 bins
75 static const int nb_gray_tags = 8;
76 static const int first_gray_tag = 9;
78 static const int _nb_tags = nb_edge_tags + 1 + nb_gray_tags;
80 inline int nb_tags() { return _nb_tags; }
81 inline int nb_scales() { return _nb_scales; }
83 inline int nb_tags_in_window(int scale, int tag, int xmin, int ymin, int xmax, int ymax) {
84 if(scale < 0 || scale >= _nb_scales) return 0;
85 if(xmin < 0) xmin = 0;
86 if(xmax >= _width_at_scale[scale]) xmax = _width_at_scale[scale] - 1;
87 if(ymin < 0) ymin = 0;
88 if(ymax >= _height_at_scale[scale]) ymax = _height_at_scale[scale] - 1;
89 if(xmin < xmax && ymin < ymax) {
90 unsigned int **tmp = _scale_edge_map[scale][tag];
91 return tmp[ymax][xmax] + tmp[ymin][xmin] - tmp[ymax][xmin] - tmp[ymin][xmax];
97 RichImage(int width, int height);
100 virtual void compute_rich_structure();
102 virtual void write(ostream *out);
104 // read does _NOT_ build the rich structure. One has to call
105 // compute_rich_structure() for that!
106 virtual void read(istream *in);
108 virtual void write_tag_png(const char *filename);