Skip to content

Commit

Permalink
core: Create file_image_size functor
Browse files Browse the repository at this point in the history
Moves a bunch of repeated code over to a helper function that just
checks the size of an image.

also: Remove excessive outptut in OrthoRasterizer
  • Loading branch information
Zack Moratto committed May 17, 2012
1 parent c5b4609 commit c191987
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 44 deletions.
7 changes: 7 additions & 0 deletions src/asp/Core/Common.cc
Expand Up @@ -118,3 +118,10 @@ bool asp::has_cam_extension( std::string const& input ) {
return true; return true;
return false; return false;
} }

Vector2i asp::file_image_size( std::string const& input ) {
boost::scoped_ptr<SrcImageResource>
rsrc( DiskImageResource::open( input ) );
Vector2i size( rsrc->cols(), rsrc->rows() );
return size;
}
2 changes: 2 additions & 0 deletions src/asp/Core/Common.h
Expand Up @@ -55,6 +55,8 @@ namespace asp {


bool has_cam_extension( std::string const& input ); bool has_cam_extension( std::string const& input );


vw::Vector2i file_image_size( std::string const& input );

template <class ImageT> template <class ImageT>
vw::DiskImageResourceGDAL* vw::DiskImageResourceGDAL*
build_gdal_rsrc( const std::string &filename, build_gdal_rsrc( const std::string &filename,
Expand Down
1 change: 0 additions & 1 deletion src/asp/Core/OrthoRasterizer.h
Expand Up @@ -182,7 +182,6 @@ namespace cartography {
BBox2i buffered_bbox = bbox; BBox2i buffered_bbox = bbox;
buffered_bbox = bbox; buffered_bbox = bbox;
buffered_bbox.expand(3.0* (1.0/m_spacing) * (1.0/m_point_spacing)); 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. // Calculate the pixel bounding boxes' location in the point domain.
// //
Expand Down
10 changes: 2 additions & 8 deletions src/asp/Sessions/ISIS/StereoSessionIsis.cc
Expand Up @@ -214,14 +214,8 @@ asp::StereoSessionIsis::pre_preprocessing_hook(std::string const& input_file1,
} }


// Getting left image size // Getting left image size
Vector2i left_size, right_size; Vector2i left_size = file_image_size( input_file1 ),
{ right_size = file_image_size( input_file2 );
boost::scoped_ptr<DiskImageResource>
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() );
}


// Apply alignment and normalization // Apply alignment and normalization
if (stereo_settings().individually_normalize == 0 ) { if (stereo_settings().individually_normalize == 0 ) {
Expand Down
59 changes: 24 additions & 35 deletions src/asp/Tools/stereo_corr.cc
Expand Up @@ -165,11 +165,10 @@ approximate_search_range( std::string const& left_image,
float i_scale = 1.0/scale; float i_scale = 1.0/scale;


// String names // String names
std::string left_ip_file = std::string
fs::path( left_image ).replace_extension("vwip").string(); left_ip_file = fs::path( left_image ).replace_extension("vwip").string(),
std::string right_ip_file = right_ip_file = fs::path( right_image ).replace_extension("vwip").string(),
fs::path( right_image ).replace_extension("vwip").string(); match_file =
std::string match_file =
fs::path( left_image ).replace_extension("").string() + "__" + fs::path( left_image ).replace_extension("").string() + "__" +
fs::path( right_image ).stem() + ".match"; fs::path( right_image ).stem() + ".match";


Expand Down Expand Up @@ -258,29 +257,26 @@ approximate_search_range( std::string const& left_image,


vw_out() << "\t * Rejecting outliers using RANSAC.\n"; vw_out() << "\t * Rejecting outliers using RANSAC.\n";
ip::remove_duplicates(matched_ip1, matched_ip2); ip::remove_duplicates(matched_ip1, matched_ip2);
std::vector<Vector3> ransac_ip1 = ip::iplist_to_vectorlist(matched_ip1); std::vector<Vector3>
std::vector<Vector3> ransac_ip2 = ip::iplist_to_vectorlist(matched_ip2); ransac_ip1 = ip::iplist_to_vectorlist(matched_ip1),
ransac_ip2 = ip::iplist_to_vectorlist(matched_ip2);
std::vector<size_t> indices; std::vector<size_t> indices;


try { try {
// Figure out the inlier threshold .. it should be about 3% of // Figure out the inlier threshold .. it should be about 3% of
// the edge lengths. This is a bit of a magic number, but I'm // the edge lengths. This is a bit of a magic number, but I'm
// pulling from experience that an inlier threshold of 30 // pulling from experience that an inlier threshold of 30
// worked best for 1024^2 AMC imagery. // worked best for 1024^2 AMC imagery.
DiskImageView<PixelT> left_sub_image(left_image);
DiskImageView<PixelT> right_sub_image(right_image);
float inlier_threshold = float inlier_threshold =
0.0075 * left_sub_image.cols() + 0.0075 * ( sum( file_image_size( left_image ) ) +
0.0075 * left_sub_image.rows() + sum( file_image_size( right_image ) ) );
0.0075 * right_sub_image.cols() +
0.0075 * right_sub_image.rows();


math::RandomSampleConsensus<math::HomographyFittingFunctor,math::InterestPointErrorMetric> math::RandomSampleConsensus<math::HomographyFittingFunctor,math::InterestPointErrorMetric>
ransac( math::HomographyFittingFunctor(), math::InterestPointErrorMetric(), inlier_threshold ); ransac( math::HomographyFittingFunctor(), math::InterestPointErrorMetric(), inlier_threshold );
Matrix<double> trans = ransac( ransac_ip1, ransac_ip2 ); Matrix<double> trans = ransac( ransac_ip1, ransac_ip2 );
vw_out(DebugMessage) << "\t * Ransac Result: " << trans << std::endl; vw_out(DebugMessage,"asp") << "\t * Ransac Result: " << trans << std::endl;
vw_out(DebugMessage) << "\t inlier thresh: " vw_out(DebugMessage,"asp") << "\t inlier thresh: "
<< inlier_threshold << " px" << std::endl; << inlier_threshold << " px" << std::endl;
indices = ransac.inlier_indices(trans, ransac_ip1, ransac_ip2 ); indices = ransac.inlier_indices(trans, ransac_ip1, ransac_ip2 );
} catch ( vw::math::RANSACErr const& e ) { } catch ( vw::math::RANSACErr const& e ) {
vw_out() << "-------------------------------WARNING---------------------------------\n"; vw_out() << "-------------------------------WARNING---------------------------------\n";
Expand Down Expand Up @@ -308,12 +304,11 @@ approximate_search_range( std::string const& left_image,
namespace ba = boost::accumulators; namespace ba = boost::accumulators;
ba::accumulator_set<float, ba::stats<ba::tag::variance> > acc_x, acc_y; ba::accumulator_set<float, ba::stats<ba::tag::variance> > acc_x, acc_y;
for (size_t i = 0; i < matched_ip1.size(); i++) { for (size_t i = 0; i < matched_ip1.size(); i++) {
Vector2f translation( i_scale*(Vector2f(matched_ip2[i].x, matched_ip2[i].y) - acc_x(i_scale * ( matched_ip2[i].x - matched_ip1[i].x ));
Vector2f(matched_ip1[i].x, matched_ip1[i].y)) ); acc_y(i_scale * ( matched_ip2[i].y - matched_ip1[i].y ));
acc_x(translation.x());
acc_y(translation.y());
} }
Vector2f mean( ba::mean(acc_x), ba::mean(acc_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)) ); Vector2f stddev( sqrt(ba::variance(acc_x)), sqrt(ba::variance(acc_y)) );
BBox2i search_range( mean - 2.5*stddev, BBox2i search_range( mean - 2.5*stddev,
mean + 2.5*stddev ); mean + 2.5*stddev );
Expand Down Expand Up @@ -386,23 +381,17 @@ void stereo_correlation( Options& opt ) {
// Pinhole + Epipolar // Pinhole + Epipolar
// Pinhole + None // Pinhole + None
// Everything else should gather IP's all the time. // Everything else should gather IP's all the time.
std::string l_sub_file = opt.out_prefix+"-L_sub.tif"; float sub_scale =
std::string r_sub_file = opt.out_prefix+"-R_sub.tif"; sum(elem_quot( file_image_size( opt.out_prefix+"-L_sub.tif" ),
float sub_scale = 0; file_image_size( opt.out_prefix+"-L.tif" ) ) ) +
{ sum(elem_quot( file_image_size( opt.out_prefix+"-R_sub.tif" ),
std::string l_org_file = opt.out_prefix+"-L.tif"; file_image_size( opt.out_prefix+"-R.tif" ) ) );
std::string r_org_file = opt.out_prefix+"-R.tif"; sub_scale /= 4.0f;
DiskImageView<uint8> l_sub(l_sub_file), r_sub(r_sub_file);
DiskImageView<uint8> 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;
}


stereo_settings().search_range = 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 { } else {
// There exists a matchfile out there. // There exists a matchfile out there.
std::vector<ip::InterestPoint> ip1, ip2; std::vector<ip::InterestPoint> ip1, ip2;
Expand Down

0 comments on commit c191987

Please sign in to comment.