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 as published
13 * by the Free Software Foundation, either version 3 of the License,
14 * or (at your option) any later version.
16 * folded-ctf is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with folded-ctf. If not, see <http://www.gnu.org/licenses/>.
28 A RichImage is an Image with all the necessary pre-computation to
29 compute the feature responses: Edge detection and local variance
30 thresholding at multiple scale, with integral images. The heavy
31 machinery and ugly coding style is motivated by performance.
39 #include "rgb_image.h"
43 class RichImage : public Image {
45 static const int _image_size_min = 8;
49 int *_width_at_scale, *_height_at_scale;
51 unsigned int *_edge_map;
53 unsigned int **_line_edge_map;
54 unsigned int ***_tag_edge_map;
55 unsigned int ****_scale_edge_map;
59 void compute_one_scale_edge_maps(int width, int height,
60 unsigned int ***scale_edge_map,
61 unsigned char *pixel_map,
62 unsigned int *sum_pixel_map,
63 unsigned int *sum_sq_pixel_map);
67 // We have 8 edge orientations
68 static const int nb_edge_tags = 8;
69 static const int first_edge_tag = 0;
71 // The variance tag is 1 if the variance of the gray levels in the
72 // 16x16 square is greater than 10
73 static const int variance_tag = 8;
75 // We quantify the grayscales into 8 bins
76 static const int nb_gray_tags = 8;
77 static const int first_gray_tag = 9;
79 static const int _nb_tags = nb_edge_tags + 1 + nb_gray_tags;
81 inline int nb_tags() { return _nb_tags; }
82 inline int nb_scales() { return _nb_scales; }
84 inline int nb_tags_in_window(int scale, int tag, int xmin, int ymin, int xmax, int ymax) {
85 if(scale < 0 || scale >= _nb_scales) return 0;
86 if(xmin < 0) xmin = 0;
87 if(xmax >= _width_at_scale[scale]) xmax = _width_at_scale[scale] - 1;
88 if(ymin < 0) ymin = 0;
89 if(ymax >= _height_at_scale[scale]) ymax = _height_at_scale[scale] - 1;
90 if(xmin < xmax && ymin < ymax) {
91 unsigned int **tmp = _scale_edge_map[scale][tag];
92 return tmp[ymax][xmax] + tmp[ymin][xmin] - tmp[ymax][xmin] - tmp[ymin][xmax];
98 RichImage(int width, int height);
101 virtual void compute_rich_structure();
103 virtual void write(ostream *out);
105 // read does _NOT_ build the rich structure. One has to call
106 // compute_rich_structure() for that!
107 virtual void read(istream *in);
109 virtual void write_tag_png(const char *filename);