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 ///////////////////////////////////////////////////////////////////////////
19 #include "materials.h"
20 #include "boosted_classifier.h"
21 #include "parsing_pool.h"
22 #include "rgb_image_subpixel.h"
24 void write_referential_png(char *filename,
27 PiReferential *referential,
30 scalar_t s = global.discrete_log_scale_to_scale(referential->common_scale());
32 RGBImage result(int(image->width() * s), int(image->height() * s));
34 for(int y = 0; y < result.height(); y++) {
35 for(int x = 0; x < result.width(); x++) {
40 for(int b = 0; b < RichImage::nb_gray_tags; b++) {
41 c += (b * 256)/RichImage::nb_gray_tags *
42 image->nb_tags_in_window(referential->common_scale(),
43 RichImage::first_gray_tag + b,
50 // for(int b = 0; b < RichImage::nb_edge_tags; b++) {
51 // c += image->nb_tags_in_window(referential->common_scale(),
52 // RichImage::first_edge_tag + b,
56 // c = 255 - (c * 255)/RichImage::nb_edge_tags;
58 // THRESHOLDED VARIANCE
60 // c = image->nb_tags_in_window(referential->common_scale(),
61 // RichImage::variance_tag,
66 result.set_pixel(x, y, c, c, c);
70 RGBImageSubpixel result_sp(&result);
73 pf->draw(&result_sp, 255, 255, 0, referential);
75 referential->draw(&result_sp, level);
78 (*global.log_stream) << "Writing " << filename << endl;
79 result_sp.write_png(filename);
82 void write_one_pi_feature_png(char *filename,
84 PoseCellHierarchy *hierarchy,
90 hierarchy->get_containing_cell(image, level,
91 image->get_target_pose(nb_target), &target_cell);
92 PiReferential referential(&target_cell);
93 RGBImage result(image->width(), image->height());
94 image->to_rgb(&result);
95 RGBImageSubpixel result_sp(&result);
96 referential.draw(&result_sp, level);
97 // pf->draw(&result_sp, 255, 255, 0, &referential);
98 result_sp.write_png(filename);
101 void write_pool_images_with_poses_and_referentials(LabelledImagePool *pool,
102 Detector *detector) {
103 LabelledImage *image;
104 char buffer[buffer_size];
106 PoseCell target_cell;
110 PoseCellHierarchy *hierarchy = new PoseCellHierarchy(pool);
112 for(int i = 0; i < min(global.nb_images, pool->nb_images()); i++) {
113 image = pool->grab_image(i);
114 RGBImage result(image->width(), image->height());
115 image->to_rgb(&result);
116 RGBImageSubpixel result_sp(&result);
118 if(global.pictures_for_article) {
119 for(int t = 0; t < image->nb_targets(); t++) {
120 image->get_target_pose(t)->draw(8, 255, 255, 255,
121 hierarchy->nb_levels() - 1, &result_sp);
124 for(int t = 0; t < image->nb_targets(); t++) {
125 image->get_target_pose(t)->draw(4, 0, 0, 0,
126 hierarchy->nb_levels() - 1, &result_sp);
129 for(int t = 0; t < image->nb_targets(); t++) {
130 image->get_target_pose(t)->draw(4, 255, 128, 0,
131 hierarchy->nb_levels() - 1, &result_sp);
135 sprintf(buffer, "/tmp/truth-%05d.png", i);
136 cout << "Writing " << buffer << endl;
137 result_sp.write_png(buffer);
138 pool->release_image(i);
141 for(int i = 0; i < min(global.nb_images, pool->nb_images()); i++) {
142 image = pool->grab_image(i);
144 RGBImage result(image->width(), image->height());
145 image->to_rgb(&result);
146 RGBImageSubpixel result_sp(&result);
150 // image->compute_rich_structure();
152 for(int t = 0; t < image->nb_targets(); t++) {
154 image->get_target_pose(t)->draw(4, 255, 0, 0,
155 hierarchy->nb_levels() - 1, &result_sp);
157 hierarchy->get_containing_cell(image,
158 hierarchy->nb_levels() - 1,
159 image->get_target_pose(t), &target_cell);
161 target_cell.get_centroid(&p);
163 p.draw(4, 0, 255, 0, hierarchy->nb_levels() - 1, &result_sp);
165 PiReferential referential(&target_cell);
167 sprintf(buffer, "/tmp/referential-%05d-%02d.png", i, u);
168 image->compute_rich_structure();
169 write_referential_png(buffer, hierarchy->nb_levels() - 1, image, &referential, 0);
172 int nb_features = 100;
173 for(int f = 0; f < nb_features; f++)
174 if(f == 0 || f ==50 || f == 53) {
175 int n_family, n_feature;
176 if(f < nb_features/2) {
180 n_family = detector->_nb_classifiers_per_level;
181 n_feature = f - nb_features/2;
183 pf = detector->_pi_feature_families[n_family]->get_feature(n_feature);
184 sprintf(buffer, "/tmp/pf-%05d-%02d-%03d.png", i, u, f);
185 write_referential_png(buffer,
186 hierarchy->nb_levels() - 1,
195 // sprintf(buffer, "/tmp/image-%05d.png", i);
196 // cout << "Writing " << buffer << endl;
197 // result_sp.write_png(buffer);
199 // if(global.write_tag_images) {
200 // sprintf(buffer, "/tmp/image-%05d_tags.png", i);
201 // cout << "Writing " << buffer << endl;
202 // image->compute_rich_structure();
203 // image->write_tag_png(buffer);
206 pool->release_image(i);
212 void write_image_with_detections(const char *filename,
213 LabelledImage *image,
214 PoseCellSet *detections,
217 RGBImage result(image->width(), image->height());
219 for(int y = 0; y < result.height(); y++) {
220 for(int x = 0; x < result.width(); x++) {
221 int c = image->value(x, y);
222 result.set_pixel(x, y, c, c, c);
226 RGBImageSubpixel result_sp(&result);
228 if(global.pictures_for_article) {
229 for(int a = 0; a < detections->nb_cells(); a++) {
231 detections->get_cell(a)->get_centroid(&pose);
232 pose.draw(8, 255, 255, 255, level, &result_sp);
234 for(int a = 0; a < detections->nb_cells(); a++) {
236 detections->get_cell(a)->get_centroid(&pose);
237 pose.draw(4, 0, 0, 0, level, &result_sp);
240 for(int a = 0; a < detections->nb_cells(); a++) {
242 detections->get_cell(a)->get_centroid(&pose);
243 pose.draw(4, 255, 128, 0, level, &result_sp);
247 (*global.log_stream) << "Writing " << filename << endl;
249 result_sp.write_png(filename);