Skip to content

Commit

Permalink
Fix image write in correlate tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottMcMichael committed Aug 23, 2017
1 parent c794845 commit 026e1c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
21 changes: 18 additions & 3 deletions src/vw/Stereo/SGM.cc
Expand Up @@ -1154,6 +1154,19 @@ create_disparity_view_subpixel(DisparityImage const& integer_disparity) {
delta_y = compute_subpixel_offset(accum_vec[min_index+y_up ], accum_vec[min_index], accum_vec[min_index+y_down ]);
}

//if (dy+delta_y == 1.5) {
// double ratio = compute_subpixel_ratio(accum_vec[min_index+y_up], accum_vec[min_index], accum_vec[min_index+y_down]);
//printf("up, center, down = %d, %d, %d, ratio = %lf\n",
// accum_vec[min_index+y_up], accum_vec[min_index], accum_vec[min_index+y_down], ratio);
// rawFile << "up = " << accum_vec[min_index+y_up] << ", center = " << accum_vec[min_index] << ", down = " << accum_vec[min_index+y_down] << ", ratio = " << ratio << ", y_up = " << y_up << ", y_down = " << y_down << ", dy = " << dy << ", min_index = " << min_index << std::endl;
//for (int j=0; j<height; ++j) {
// for (int i=0; i<width; ++i) {
// rawFile << accum_vec[j*height+i];
// }
// rawFile << std::endl;
//}
//}

// To assist development, write the internal subpixel input ratio to a file.
//double temp = compute_subpixel_ratio(accum_vec[min_index+x_left], accum_vec[min_index], accum_vec[min_index+x_right]);
//rawFile << temp << std::endl;
Expand All @@ -1169,9 +1182,11 @@ create_disparity_view_subpixel(DisparityImage const& integer_disparity) {
}
} // End col loop
} // End row loop

percent_bad /= (double)(m_num_output_rows*m_num_output_cols);
vw_out(DebugMessage, "stereo") << "Subpixel interpolation failure percentage: " << percent_bad << std::endl;

if (m_subpixel_type == SUBPIXEL_PARABOLA) { // Only ever failures with this mode
percent_bad /= (double)(m_num_output_rows*m_num_output_cols);
vw_out(DebugMessage, "stereo") << "Subpixel interpolation failure percentage: " << percent_bad << std::endl;
}

// Write these out for debugging/development
//write_image( "subpixel_disp.tif", disparity );
Expand Down
17 changes: 11 additions & 6 deletions src/vw/tools/correlate.cc
Expand Up @@ -36,6 +36,7 @@
#include <vw/Stereo/CostFunctions.h>
#include <vw/Stereo/PreFilter.h>
#include <vw/Stereo/DisparityMap.h>
#include <vw/Cartography/GeoReferenceUtils.h>

#include <boost/program_options.hpp>
#include <boost/filesystem/operations.hpp>
Expand Down Expand Up @@ -189,7 +190,7 @@ int main( int argc, char *argv[] ) {

// TODO: Hook up to options!
SemiGlobalMatcher::SgmSubpixelMode sgm_subpixel_mode = SemiGlobalMatcher::SUBPIXEL_LC_BLEND;
Vector2i sgm_search_buffer(2,2);
Vector2i sgm_search_buffer(4,3);
size_t memory_limit_mb = 1024*4;

ImageViewRef<PixelMask<Vector2f> > disparity_map;
Expand Down Expand Up @@ -254,11 +255,15 @@ int main( int argc, char *argv[] ) {
// Actually invoke the raster
{
vw::Timer corr_timer("Correlation Time");
boost::scoped_ptr<DiskImageResource> r(DiskImageResource::create("disparity.tif",disparity_map.format()));
r->set_block_write_size( Vector2i(vw::vw_settings().default_tile_size(),
vw::vw_settings().default_tile_size()) );
block_write_image( *r, disparity_map,
TerminalProgressCallback( "", "Rendering: ") );
cartography::GdalWriteOptions geo_opt;
geo_opt.raster_tile_size = Vector2i(1024, 1024);
if (stereo_algorithm == CORRELATION_WINDOW) {
block_write_gdal_image("disparity.tif", disparity_map, geo_opt);
}
else { // SGM/MGM needs to be rasterized in a single tile.
ImageView<PixelMask<Vector2f> > result = disparity_map;
block_write_gdal_image("disparity.tif", result, geo_opt);
}
}

//// Write disparity debug images
Expand Down

0 comments on commit 026e1c5

Please sign in to comment.