diff --git a/src/asp/Core/Common.cc b/src/asp/Core/Common.cc index 4f9faee90..524fa93a7 100644 --- a/src/asp/Core/Common.cc +++ b/src/asp/Core/Common.cc @@ -118,3 +118,10 @@ bool asp::has_cam_extension( std::string const& input ) { return true; return false; } + +Vector2i asp::file_image_size( std::string const& input ) { + boost::scoped_ptr + rsrc( DiskImageResource::open( input ) ); + Vector2i size( rsrc->cols(), rsrc->rows() ); + return size; +} diff --git a/src/asp/Core/Common.h b/src/asp/Core/Common.h index eea41220b..8932b5106 100644 --- a/src/asp/Core/Common.h +++ b/src/asp/Core/Common.h @@ -55,6 +55,8 @@ namespace asp { bool has_cam_extension( std::string const& input ); + vw::Vector2i file_image_size( std::string const& input ); + template vw::DiskImageResourceGDAL* build_gdal_rsrc( const std::string &filename, diff --git a/src/asp/Core/OrthoRasterizer.h b/src/asp/Core/OrthoRasterizer.h index f68ee6c84..1e0e74e50 100644 --- a/src/asp/Core/OrthoRasterizer.h +++ b/src/asp/Core/OrthoRasterizer.h @@ -182,7 +182,6 @@ namespace cartography { BBox2i buffered_bbox = bbox; buffered_bbox = bbox; buffered_bbox.expand(3.0* (1.0/m_spacing) * (1.0/m_point_spacing)); - vw_out(DebugMessage,"asp") << "Expanding raster bbox by " << 3.0 * (1.0/m_spacing) * (1.0/m_point_spacing) << " pixels.\n"; // Calculate the pixel bounding boxes' location in the point domain. // diff --git a/src/asp/Sessions/ISIS/StereoSessionIsis.cc b/src/asp/Sessions/ISIS/StereoSessionIsis.cc index 468c95133..86fad4fc5 100644 --- a/src/asp/Sessions/ISIS/StereoSessionIsis.cc +++ b/src/asp/Sessions/ISIS/StereoSessionIsis.cc @@ -214,14 +214,8 @@ asp::StereoSessionIsis::pre_preprocessing_hook(std::string const& input_file1, } // Getting left image size - Vector2i left_size, right_size; - { - boost::scoped_ptr - left_rsrc( DiskImageResource::open( input_file1 ) ), - right_rsrc( DiskImageResource::open( input_file2 ) ); - left_size = Vector2i( left_rsrc->cols(), left_rsrc->rows() ); - right_size = Vector2i( right_rsrc->cols(), right_rsrc->rows() ); - } + Vector2i left_size = file_image_size( input_file1 ), + right_size = file_image_size( input_file2 ); // Apply alignment and normalization if (stereo_settings().individually_normalize == 0 ) { diff --git a/src/asp/Tools/stereo_corr.cc b/src/asp/Tools/stereo_corr.cc index 407eb11c0..43c0848a5 100644 --- a/src/asp/Tools/stereo_corr.cc +++ b/src/asp/Tools/stereo_corr.cc @@ -165,11 +165,10 @@ approximate_search_range( std::string const& left_image, float i_scale = 1.0/scale; // String names - std::string left_ip_file = - fs::path( left_image ).replace_extension("vwip").string(); - std::string right_ip_file = - fs::path( right_image ).replace_extension("vwip").string(); - std::string match_file = + std::string + left_ip_file = fs::path( left_image ).replace_extension("vwip").string(), + right_ip_file = fs::path( right_image ).replace_extension("vwip").string(), + match_file = fs::path( left_image ).replace_extension("").string() + "__" + fs::path( right_image ).stem() + ".match"; @@ -258,8 +257,9 @@ approximate_search_range( std::string const& left_image, vw_out() << "\t * Rejecting outliers using RANSAC.\n"; ip::remove_duplicates(matched_ip1, matched_ip2); - std::vector ransac_ip1 = ip::iplist_to_vectorlist(matched_ip1); - std::vector ransac_ip2 = ip::iplist_to_vectorlist(matched_ip2); + std::vector + ransac_ip1 = ip::iplist_to_vectorlist(matched_ip1), + ransac_ip2 = ip::iplist_to_vectorlist(matched_ip2); std::vector indices; try { @@ -267,20 +267,16 @@ approximate_search_range( std::string const& left_image, // the edge lengths. This is a bit of a magic number, but I'm // pulling from experience that an inlier threshold of 30 // worked best for 1024^2 AMC imagery. - DiskImageView left_sub_image(left_image); - DiskImageView right_sub_image(right_image); float inlier_threshold = - 0.0075 * left_sub_image.cols() + - 0.0075 * left_sub_image.rows() + - 0.0075 * right_sub_image.cols() + - 0.0075 * right_sub_image.rows(); + 0.0075 * ( sum( file_image_size( left_image ) ) + + sum( file_image_size( right_image ) ) ); math::RandomSampleConsensus ransac( math::HomographyFittingFunctor(), math::InterestPointErrorMetric(), inlier_threshold ); Matrix trans = ransac( ransac_ip1, ransac_ip2 ); - vw_out(DebugMessage) << "\t * Ransac Result: " << trans << std::endl; - vw_out(DebugMessage) << "\t inlier thresh: " - << inlier_threshold << " px" << std::endl; + vw_out(DebugMessage,"asp") << "\t * Ransac Result: " << trans << std::endl; + vw_out(DebugMessage,"asp") << "\t inlier thresh: " + << inlier_threshold << " px" << std::endl; indices = ransac.inlier_indices(trans, ransac_ip1, ransac_ip2 ); } catch ( vw::math::RANSACErr const& e ) { vw_out() << "-------------------------------WARNING---------------------------------\n"; @@ -308,12 +304,11 @@ approximate_search_range( std::string const& left_image, namespace ba = boost::accumulators; ba::accumulator_set > acc_x, acc_y; for (size_t i = 0; i < matched_ip1.size(); i++) { - Vector2f translation( i_scale*(Vector2f(matched_ip2[i].x, matched_ip2[i].y) - - Vector2f(matched_ip1[i].x, matched_ip1[i].y)) ); - acc_x(translation.x()); - acc_y(translation.y()); + acc_x(i_scale * ( matched_ip2[i].x - matched_ip1[i].x )); + acc_y(i_scale * ( matched_ip2[i].y - matched_ip1[i].y )); } Vector2f mean( ba::mean(acc_x), ba::mean(acc_y) ); + vw_out(DebugMessage,"asp") << "Mean search is : " << mean << std::endl; Vector2f stddev( sqrt(ba::variance(acc_x)), sqrt(ba::variance(acc_y)) ); BBox2i search_range( mean - 2.5*stddev, mean + 2.5*stddev ); @@ -386,23 +381,17 @@ void stereo_correlation( Options& opt ) { // Pinhole + Epipolar // Pinhole + None // Everything else should gather IP's all the time. - std::string l_sub_file = opt.out_prefix+"-L_sub.tif"; - std::string r_sub_file = opt.out_prefix+"-R_sub.tif"; - float sub_scale = 0; - { - std::string l_org_file = opt.out_prefix+"-L.tif"; - std::string r_org_file = opt.out_prefix+"-R.tif"; - DiskImageView l_sub(l_sub_file), r_sub(r_sub_file); - DiskImageView l_org(l_org_file), r_org(r_org_file); - sub_scale += float(l_sub.cols())/float(l_org.cols()); - sub_scale += float(r_sub.cols())/float(r_org.cols()); - sub_scale += float(l_sub.rows())/float(l_org.rows()); - sub_scale += float(r_sub.rows())/float(r_org.rows()); - sub_scale /= 4; - } + float sub_scale = + sum(elem_quot( file_image_size( opt.out_prefix+"-L_sub.tif" ), + file_image_size( opt.out_prefix+"-L.tif" ) ) ) + + sum(elem_quot( file_image_size( opt.out_prefix+"-R_sub.tif" ), + file_image_size( opt.out_prefix+"-R.tif" ) ) ); + sub_scale /= 4.0f; stereo_settings().search_range = - approximate_search_range( l_sub_file, r_sub_file, sub_scale ); + approximate_search_range( opt.out_prefix+"-L_sub.tif", + opt.out_prefix+"-R_sub.tif", + sub_scale ); } else { // There exists a matchfile out there. std::vector ip1, ip2;