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 cout << "Writing " << filename << endl;
79 result_sp.write_png(filename);
82 void write_pool_images_with_poses_and_referentials(LabelledImagePool *pool,
85 char buffer[buffer_size];
91 PoseCellHierarchy *hierarchy = new PoseCellHierarchy(pool);
93 if(global.material_feature_nb < 0) {
94 for(int i = 0; i < min(global.nb_images, pool->nb_images()); i++) {
95 image = pool->grab_image(i);
96 RGBImage result(image->width(), image->height());
97 image->to_rgb(&result);
98 RGBImageSubpixel result_sp(&result);
100 if(global.pictures_for_article) {
101 for(int t = 0; t < image->nb_targets(); t++) {
102 image->get_target_pose(t)->draw(8, 255, 255, 255,
103 hierarchy->nb_levels() - 1, &result_sp);
106 for(int t = 0; t < image->nb_targets(); t++) {
107 image->get_target_pose(t)->draw(4, 0, 0, 0,
108 hierarchy->nb_levels() - 1, &result_sp);
111 for(int t = 0; t < image->nb_targets(); t++) {
112 image->get_target_pose(t)->draw(4, 255, 128, 0,
113 hierarchy->nb_levels() - 1, &result_sp);
117 sprintf(buffer, "/tmp/truth-%05d.png", i);
118 cout << "Writing " << buffer << endl;
119 result_sp.write_png(buffer);
120 pool->release_image(i);
124 for(int i = 0; i < min(global.nb_images, pool->nb_images()); i++) {
125 image = pool->grab_image(i);
127 RGBImage result(image->width(), image->height());
128 image->to_rgb(&result);
129 RGBImageSubpixel result_sp(&result);
131 // image->compute_rich_structure();
133 for(int t = 0; t < image->nb_targets(); t++) {
135 image->get_target_pose(t)->draw(4, 255, 0, 0,
136 hierarchy->nb_levels() - 1, &result_sp);
138 hierarchy->get_containing_cell(image,
139 hierarchy->nb_levels() - 1,
140 image->get_target_pose(t), &target_cell);
142 target_cell.get_centroid(&p);
144 p.draw(4, 0, 255, 0, hierarchy->nb_levels() - 1, &result_sp);
146 PiReferential referential(&target_cell);
148 image->compute_rich_structure();
150 if(global.material_feature_nb < 0) {
151 sprintf(buffer, "/tmp/referential-%05d-%02d.png", i, t);
152 write_referential_png(buffer, hierarchy->nb_levels() - 1, image, &referential, 0);
153 } else if(detector) {
155 int n_feature = global.material_feature_nb;
156 while(n_feature > detector->_pi_feature_families[n_family]->nb_features()) {
158 n_feature -= detector->_pi_feature_families[n_family]->nb_features();
160 pf = detector->_pi_feature_families[n_family]->get_feature(n_feature);
161 sprintf(buffer, "/tmp/pf-%05d-%02d-%05d.png", i, t, global.material_feature_nb);
162 write_referential_png(buffer,
163 hierarchy->nb_levels() - 1,
170 pool->release_image(i);
176 void write_image_with_detections(const char *filename,
177 LabelledImage *image,
178 PoseCellSet *detections,
181 RGBImage result(image->width(), image->height());
183 for(int y = 0; y < result.height(); y++) {
184 for(int x = 0; x < result.width(); x++) {
185 int c = image->value(x, y);
186 result.set_pixel(x, y, c, c, c);
190 RGBImageSubpixel result_sp(&result);
192 if(global.pictures_for_article) {
193 for(int a = 0; a < detections->nb_cells(); a++) {
195 detections->get_cell(a)->get_centroid(&pose);
196 pose.draw(8, 255, 255, 255, level, &result_sp);
198 for(int a = 0; a < detections->nb_cells(); a++) {
200 detections->get_cell(a)->get_centroid(&pose);
201 pose.draw(4, 0, 0, 0, level, &result_sp);
204 for(int a = 0; a < detections->nb_cells(); a++) {
206 detections->get_cell(a)->get_centroid(&pose);
207 pose.draw(4, 255, 128, 0, level, &result_sp);
211 cout << "Writing " << filename << endl;
212 result_sp.write_png(filename);