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 //
16 // (C) Idiap Research Institute //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
19 ///////////////////////////////////////////////////////////////////////////
21 #include "materials.h"
22 #include "boosted_classifier.h"
23 #include "parsing_pool.h"
24 #include "rgb_image_subpixel.h"
26 void write_referential_png(char *filename,
29 PiReferential *referential,
32 scalar_t s = global.discrete_log_scale_to_scale(referential->common_scale());
34 RGBImage result(int(image->width() * s), int(image->height() * s));
36 for(int y = 0; y < result.height(); y++) {
37 for(int x = 0; x < result.width(); x++) {
42 for(int b = 0; b < RichImage::nb_gray_tags; b++) {
43 c += (b * 256)/RichImage::nb_gray_tags *
44 image->nb_tags_in_window(referential->common_scale(),
45 RichImage::first_gray_tag + b,
52 // for(int b = 0; b < RichImage::nb_edge_tags; b++) {
53 // c += image->nb_tags_in_window(referential->common_scale(),
54 // RichImage::first_edge_tag + b,
58 // c = 255 - (c * 255)/RichImage::nb_edge_tags;
60 // THRESHOLDED VARIANCE
62 // c = image->nb_tags_in_window(referential->common_scale(),
63 // RichImage::variance_tag,
68 result.set_pixel(x, y, c, c, c);
72 RGBImageSubpixel result_sp(&result);
75 pf->draw(&result_sp, 255, 255, 0, referential);
77 referential->draw(&result_sp, level);
80 cout << "Writing " << filename << endl;
81 result_sp.write_png(filename);
84 void write_pool_images_with_poses_and_referentials(LabelledImagePool *pool,
87 char buffer[buffer_size];
93 PoseCellHierarchy *hierarchy = new PoseCellHierarchy(pool);
95 if(global.material_feature_nb < 0) {
96 for(int i = 0; i < min(global.nb_images, pool->nb_images()); i++) {
97 image = pool->grab_image(i);
98 RGBImage result(image->width(), image->height());
99 image->to_rgb(&result);
100 RGBImageSubpixel result_sp(&result);
102 if(global.pictures_for_article) {
103 for(int t = 0; t < image->nb_targets(); t++) {
104 image->get_target_pose(t)->draw(8, 255, 255, 255,
105 hierarchy->nb_levels() - 1, &result_sp);
108 for(int t = 0; t < image->nb_targets(); t++) {
109 image->get_target_pose(t)->draw(4, 0, 0, 0,
110 hierarchy->nb_levels() - 1, &result_sp);
113 for(int t = 0; t < image->nb_targets(); t++) {
114 image->get_target_pose(t)->draw(4, 255, 128, 0,
115 hierarchy->nb_levels() - 1, &result_sp);
119 sprintf(buffer, "/tmp/truth-%05d.png", i);
120 cout << "Writing " << buffer << endl;
121 result_sp.write_png(buffer);
122 pool->release_image(i);
126 for(int i = 0; i < min(global.nb_images, pool->nb_images()); i++) {
127 image = pool->grab_image(i);
129 RGBImage result(image->width(), image->height());
130 image->to_rgb(&result);
131 RGBImageSubpixel result_sp(&result);
133 // image->compute_rich_structure();
135 for(int t = 0; t < image->nb_targets(); t++) {
137 image->get_target_pose(t)->draw(4, 255, 0, 0,
138 hierarchy->nb_levels() - 1, &result_sp);
140 hierarchy->get_containing_cell(image,
141 hierarchy->nb_levels() - 1,
142 image->get_target_pose(t), &target_cell);
144 target_cell.get_centroid(&p);
146 p.draw(4, 0, 255, 0, hierarchy->nb_levels() - 1, &result_sp);
148 PiReferential referential(&target_cell);
150 image->compute_rich_structure();
152 if(global.material_feature_nb < 0) {
153 sprintf(buffer, "/tmp/referential-%05d-%02d.png", i, t);
154 write_referential_png(buffer, hierarchy->nb_levels() - 1, image, &referential, 0);
155 } else if(detector) {
157 int n_feature = global.material_feature_nb;
158 while(n_feature > detector->_pi_feature_families[n_family]->nb_features()) {
160 n_feature -= detector->_pi_feature_families[n_family]->nb_features();
162 pf = detector->_pi_feature_families[n_family]->get_feature(n_feature);
163 sprintf(buffer, "/tmp/pf-%05d-%02d-%05d.png", i, t, global.material_feature_nb);
164 write_referential_png(buffer,
165 hierarchy->nb_levels() - 1,
172 pool->release_image(i);
178 void write_image_with_detections(const char *filename,
179 LabelledImage *image,
180 PoseCellSet *detections,
183 RGBImage result(image->width(), image->height());
185 for(int y = 0; y < result.height(); y++) {
186 for(int x = 0; x < result.width(); x++) {
187 int c = image->value(x, y);
188 result.set_pixel(x, y, c, c, c);
192 RGBImageSubpixel result_sp(&result);
194 if(global.pictures_for_article) {
195 for(int a = 0; a < detections->nb_cells(); a++) {
197 detections->get_cell(a)->get_centroid(&pose);
198 pose.draw(8, 255, 255, 255, level, &result_sp);
200 for(int a = 0; a < detections->nb_cells(); a++) {
202 detections->get_cell(a)->get_centroid(&pose);
203 pose.draw(4, 0, 0, 0, level, &result_sp);
206 for(int a = 0; a < detections->nb_cells(); a++) {
208 detections->get_cell(a)->get_centroid(&pose);
209 pose.draw(4, 255, 128, 0, level, &result_sp);
213 cout << "Writing " << filename << endl;
214 result_sp.write_png(filename);