2 ///////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation. //
7 // This program is distributed in the hope that it will be useful, but //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
10 // General Public License for more details. //
12 // You should have received a copy of the GNU General Public License //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
15 // Written by Francois Fleuret, (C) IDIAP //
16 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
17 ///////////////////////////////////////////////////////////////////////////
21 This class implements the multi-scale basic edge features on the
22 images. The heavy machinery and ugly coding style is motivated by
31 #include "rgb_image.h"
35 class RichImage : public Image {
37 static const int _image_size_min = 8;
41 int *_width_at_scale, *_height_at_scale;
43 unsigned int *_edge_map;
45 unsigned int **_line_edge_map;
46 unsigned int ***_tag_edge_map;
47 unsigned int ****_scale_edge_map;
51 void compute_one_scale_edge_maps(int width, int height,
52 unsigned int ***scale_edge_map,
53 unsigned char *pixel_map,
54 unsigned int *sum_pixel_map,
55 unsigned int *sum_sq_pixel_map);
59 // We have 8 edge orientations
60 static const int nb_edge_tags = 8;
61 static const int first_edge_tag = 0;
63 // The variance tag is 1 if the variance of the gray levels in the
64 // 16x16 square is greater than 10
65 static const int variance_tag = 8;
67 // We quantify the grayscales into 8 bins
68 static const int nb_gray_tags = 8;
69 static const int first_gray_tag = 9;
71 static const int _nb_tags = nb_edge_tags + 1 + nb_gray_tags;
73 inline int nb_tags() { return _nb_tags; }
74 inline int nb_scales() { return _nb_scales; }
76 inline int nb_tags_in_window(int scale, int tag, int xmin, int ymin, int xmax, int ymax) {
77 if(scale < 0 || scale >= _nb_scales) return 0;
78 if(xmin < 0) xmin = 0;
79 if(xmax >= _width_at_scale[scale]) xmax = _width_at_scale[scale] - 1;
80 if(ymin < 0) ymin = 0;
81 if(ymax >= _height_at_scale[scale]) ymax = _height_at_scale[scale] - 1;
82 if(xmin < xmax && ymin < ymax) {
83 unsigned int **tmp = _scale_edge_map[scale][tag];
84 return tmp[ymax][xmax] + tmp[ymin][xmin] - tmp[ymax][xmin] - tmp[ymin][xmax];
90 RichImage(int width, int height);
93 virtual void compute_rich_structure();
94 virtual void crop(int xmin, int ymin, int width, int height);
96 virtual void write(ostream *out);
98 // read does _NOT_ build the rich structure. One has to call
99 // compute_rich_structure() for that!
100 virtual void read(istream *in);
102 virtual void write_tag_png(const char *filename);