[r36635]: trunk / contrib / brl / bseg / boxm2 / volm / exe / boxm2_volumetric_evaluate_roi.cxx  Maximize  Restore  History

Download this file

223 lines (204 with data), 8.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//:
// \file
// \executable to read score profile from generated probability map for threshold ranging from 0.4 to 0.9
//
//
// \author Yi Dong
// \date Feb 18, 2013
#include <volm/volm_io.h>
#include <volm/volm_tile.h>
#include <vul/vul_arg.h>
#include <vul/vul_file.h>
#include <vil/vil_save.h>
#include <vil/vil_load.h>
#include <vcl_set.h>
#include <vcl_ios.h>
// generate gt hypos
int main(int argc, char** argv)
{
vul_arg<vcl_string> gt_file("-gt_locs", "file with the gt locs of all test cases", "");
vul_arg<vcl_string> out_root("-out_rt", "experiment output root", "");
vul_arg<unsigned> pass_id("-pass", "from pass 0 to pass 1", 1);
vul_arg_parse(argc, argv);
vcl_cout << "argc: " << argc << vcl_endl;
vcl_stringstream log;
if (out_root().compare("") == 0 ||
gt_file().compare("") == 0 ||
pass_id() > 2)
{
log << "EXE_ARGUMENT_ERROR!\n";
vul_arg_display_usage_and_exit();
volm_io::write_composer_log(out_root(), log.str());
volm_io::write_log(out_root(), log.str());
vcl_cerr << log.str();
return volm_io::EXE_ARGUMENT_ERROR;
}
// read gt location, i.e., lat and lon
if (!vul_file::exists(gt_file())) {
log << "ERROR : can not find ground truth position file -->" << gt_file() << '\n';
volm_io::write_composer_log(out_root(), log.str());
volm_io::write_log(out_root(), log.str());
vcl_cerr << log.str();
return volm_io::EXE_ARGUMENT_ERROR;
}
vcl_vector<vcl_pair<vgl_point_3d<double>, vcl_pair<vcl_string, vcl_string> > > samples;
/* unsigned int cnt = */ volm_io::read_gt_file(gt_file(), samples);
// the overall ROI for each test_image
// key -- test_img_id, vector< gt_max_score, ROI for different thres, total_pixel_evaluated >
vcl_map<unsigned, vcl_vector<float> > test_img_roi;
vcl_vector<float> thresholds;
for (unsigned i = 4; i < 10; i++) {
thresholds.push_back(0.1*i);
}
for (unsigned id = 0; id < 100; id++) {
vcl_stringstream out_folder;
if (id < 10)
out_folder << out_root() << "/p1a_test1_0" << id;
else
out_folder << out_root() << "/p1a_test1_" << id;
//vcl_cout << "out_folder = " << out_folder.str() << vcl_endl;
if (!vul_file::is_directory(out_folder.str())) {
continue;
}
vcl_cout << " we have test image folder --> " << out_folder.str() << vcl_endl;
vcl_cout << " with image category --> " << samples[id].second.second << vcl_endl;
vcl_stringstream log_test_img;
vcl_string log_file = out_folder.str() + "/evaluate_roi_log.xml";
// calculate roi for current valid out_folder
// cnt_map -- key is the thresholds, element --- cnt_below, total pixel count, total pixel uncount
vcl_map<float, vcl_vector<unsigned> > cnt_map;
for (vcl_vector<float>::iterator vit = thresholds.begin(); vit != thresholds.end(); ++vit) {
vcl_vector<unsigned> cnt_vec(3,0);
vcl_pair<float, vcl_vector<unsigned> > cnt_pair;
cnt_pair.first = *vit; cnt_pair.second = cnt_vec;
cnt_map.insert(cnt_pair);
}
// test
//vcl_map<float, vcl_vector<unsigned> >::iterator mit = cnt_map.begin();
//for (; mit != cnt_map.end(); ++mit) {
// vcl_cout << "\nthres = " << mit->first << " ---> ";
// for (vcl_vector<unsigned>::iterator vit = mit->second.begin(); vit != mit->second.end(); ++vit)
// vcl_cout << *vit << ' ';
//}
// create tile based on current image category
vcl_vector<volm_tile> tiles;
if (samples[id].second.second == "desert")
tiles = volm_tile::generate_p1_wr1_tiles();
else
tiles = volm_tile::generate_p1_wr2_tiles();
float gt_score = 0.0f;
// loop over all tiles of current test images
for (unsigned i = 0; i < tiles.size(); i++) {
vcl_string img_name = out_folder.str() + "/" + "ProbMap_" + tiles[i].get_string() + ".tif";
if (!vul_file::exists(img_name)) {
log_test_img << " WARNING: missing prob_map: " << img_name << '\n';
volm_io::write_post_processing_log(log_file, log_test_img.str());
vcl_cerr << log_test_img.str();
continue;
}
vil_image_view<float> tile_img = vil_load(img_name.c_str());
for (unsigned ii = 0; ii < tile_img.ni(); ii++) {
for (unsigned jj = 0; jj < tile_img.nj(); jj++) {
// loop over all threshold
for ( vcl_map<float, vcl_vector<unsigned> >::iterator mit = cnt_map.begin(); mit != cnt_map.end(); ++mit)
{
if (tile_img(ii, jj) < 0)
mit->second[2]++;
else {
mit->second[1]++;
if (tile_img(ii, jj) < mit->first)
mit->second[0]++;
}
}
}
}
// search for the maximum score for ground truth location
unsigned u, v;
if (tiles[i].global_to_img(samples[id].first.x(), samples[id].first.y(), u, v)) {
if (u < tile_img.ni() && v < tile_img.nj())
gt_score = tile_img(u,v);
log_test_img << "\t id = " << id << ", GT location: " << samples[id].first.x() << ", "
<< samples[id].first.y() << " is at pixel: "
<< u << ", " << v << " in tile " << i << " and has value: "
<< gt_score << '\n';
volm_io::write_post_processing_log(log_file, log_test_img.str());
vcl_cerr << log_test_img.str();
}
} // end of tile loop
// calculate ROI, save the gt_score and ROI for current test_id
vcl_vector<float> score_roi;
score_roi.push_back(gt_score);
for (vcl_map<float, vcl_vector<unsigned> >::iterator mit = cnt_map.begin();
mit != cnt_map.end(); ++mit)
{
float roi = (float)mit->second[0]/mit->second[1];
score_roi.push_back(roi);
}
score_roi.push_back(cnt_map.begin()->second[1]);
vcl_pair<unsigned, vcl_vector<float> > pair_roi;
pair_roi.first = id;
pair_roi.second = score_roi;
test_img_roi.insert(pair_roi);
#if 1
// create png tile images for different thresholds, only generate png tile prob_map with thres smaller than ground truth score
for (unsigned ti = 0; ti < tiles.size(); ti++) {
vcl_string img_name = out_folder.str() + "/" + "ProbMap_" + tiles[ti].get_string() + ".tif";
if (!vul_file::exists(img_name)) {
log_test_img << " WARNING: missing prob_map: " << img_name << '\n';
volm_io::write_post_processing_log(log_file, log_test_img.str());
vcl_cerr << log_test_img.str();
continue;
}
vil_image_view<float> tile_img = vil_load(img_name.c_str());
for (vcl_vector<float>::iterator vit = thresholds.begin(); vit != thresholds.end(); ++vit) {
if (*vit < gt_score) {
vil_image_view<vxl_byte> out_png(tile_img.ni(), tile_img.nj());
out_png.fill(volm_io::UNEVALUATED);
// loop over current tile image to rescale the score to [0, 255]
for (unsigned ii = 0; ii < tile_img.ni(); ii++) {
for (unsigned jj = 0; jj< tile_img.nj(); jj++) {
if (tile_img(ii, jj) > 0)
out_png(ii, jj) = volm_io::scale_score_to_1_255(*vit, tile_img(ii,jj));
}
}
// save the image
vcl_stringstream out_png_name;
out_png_name << out_folder.str() << "/ProbMap_" << tiles[ti].get_string() << "_thres_" << *vit << ".png";
vil_save(out_png, (out_png_name.str()).c_str());
}
}
}
#endif
} // end of test_id loop
vcl_string eoi_file = out_root() + "/roi_result.txt";
vcl_ofstream fout(eoi_file.c_str());
fout << " thresholds\n"
<< " test_id gt_loc_score total_locs ";
for (vcl_vector<float>::iterator vit = thresholds.begin(); vit != thresholds.end(); ++vit) {
fout.setf(vcl_ios_right);
fout.precision(2); fout.fill(' '); fout.width(*vit > 0.6 ? 13 : 10);
fout << *vit;
}
fout << '\n';
fout.setf(vcl_ios_right);
vcl_map<unsigned, vcl_vector<float> >::iterator mit = test_img_roi.begin();
for (; mit != test_img_roi.end(); ++mit) {
vcl_stringstream out_str;
if (mit->first < 10) out_str << "p1a_test1_0" << mit->first;
else out_str << "p1a_test1_" << mit->first;
fout << out_str.str();
fout.precision(5); fout.width(13); fout.fill(' ');
fout << mit->second[0] << ' ';
unsigned tot_loc = mit->second[mit->second.size()-1];
fout.width(13); fout.fill(' ');
fout << tot_loc << " ";
for (unsigned i = 1; i < 7; i++) {
fout.setf(vcl_ios_right);
fout.precision(5); fout.width(12); fout.fill(' ');
fout << mit->second[i];
}
fout << '\n';
}
fout.close();
return volm_io::SUCCESS;
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks