Skip to content

Commit

Permalink
Code formatting;
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-alexandrov committed Oct 19, 2023
1 parent 29e6cd6 commit ff09d53
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 38 deletions.
5 changes: 3 additions & 2 deletions docs/bundle_adjustment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ If desired, these csv files can be converted to a DEM with
--csv-format 1:lon,2:lat,4:height_above_datum

then one can look at their statistics, also have them colorized, and
viewed in ``stereo_gui``.
viewed in ``stereo_gui`` (:numref:`plot_csv`).

This file also shows how often each feature is seen in the images, so,
if three images are present, hopefully many features will be seen three
Expand Down Expand Up @@ -804,6 +804,7 @@ documentation of all options above.
some ridges having been missed). Those do not affect the optimization. Using
mapprojected images would have helped with this. The ultimate check will be
the comparison with LOLA RDR (:numref:`kaguya_intrinsics_alignment_diff`).
Plotted with ``stereo_gui`` (:numref:`plot_csv`).

Recreation of the stereo DEMs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -872,7 +873,7 @@ KaguyaTC is already reasonably well-aligned.
The signed difference between aligned stereo DEMs and LOLA RDR before (top)
and after (bottom) refinement of distortion. (Blue = -20 meters, red = 20
meters.) It can be seen that the warping of the DEMs due to distortion is much
reduced.
reduced. Plotted with ``stereo_gui`` (:numref:`plot_csv`).

.. _custom_ip:

Expand Down
8 changes: 5 additions & 3 deletions docs/tools/stereo_gui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ Hillshaded images can also be created with the ``hillshade`` tool
Displaying colorized images, with a colorbar and axes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``stereo_gui`` can have images be colorized on-the-fly
by mapping intensities to colors of a given colormap. The results
are be plotted with a colorbar and axes (with ticks).
``stereo_gui`` can have images be colorized on-the-fly by mapping intensities to
colors of a given colormap. The results are plotted with a colorbar and axes
(with ticks).

CSV files can be shown with a colorbar as well.

An example invocation is as follows::

Expand Down
11 changes: 7 additions & 4 deletions src/asp/Sessions/StereoSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,11 @@ StereoSession::camera_model(std::string const& image_file, std::string const& ca
image_file);

if (camera_file == "") // No camera file provided, use the image file.
m_camera_model[image_cam_pair] = load_camera_model(image_file, image_file, pixel_offset);
m_camera_model[image_cam_pair]
= load_camera_model(image_file, image_file, pixel_offset);
else // Camera file provided
m_camera_model[image_cam_pair] = load_camera_model(image_file, camera_file, pixel_offset);
m_camera_model[image_cam_pair]
= load_camera_model(image_file, camera_file, pixel_offset);

return m_camera_model[image_cam_pair];
}
Expand Down Expand Up @@ -368,7 +370,8 @@ void StereoSession::preprocessing_hook(bool adjust_left_image_size,

// Generate aligned versions of the input images according to the
// options.
vw_out() << "\t--> Applying alignment method: " << stereo_settings().alignment_method << "\n";
vw_out() << "\t--> Applying alignment method: "
<< stereo_settings().alignment_method << "\n";
if (stereo_settings().alignment_method == "epipolar") {

epipolar_alignment(left_masked_image, right_masked_image, ext_nodata,
Expand Down Expand Up @@ -689,7 +692,7 @@ shared_preprocessing_hook(vw::GdalWriteOptions & options,
return false; // don't exit early
}

void StereoSession::read_bathy_masks(float & left_bathy_nodata, float & right_bathy_nodata,
void StereoSession::read_bathy_masks(float & left_bathy_nodata, float & right_bathy_nodata,
vw::ImageViewRef<vw::PixelMask<float>> & left_bathy_mask,
vw::ImageViewRef<vw::PixelMask<float>> & right_bathy_mask) {

Expand Down
6 changes: 4 additions & 2 deletions src/asp/Tools/stereo_corr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ SemiGlobalMatcher::SgmSubpixelMode get_sgm_subpixel_mode() {
}

// Read the search range from D_sub, and scale it to the full image
void read_search_range_from_D_sub(std::string const& d_sub_file, ASPGlobalOptions const& opt){
void read_search_range_from_D_sub(std::string const& d_sub_file,
ASPGlobalOptions const& opt){

// No D_sub is generated or should be used for seed mode 0.
if (stereo_settings().seed_mode == 0)
Expand Down Expand Up @@ -621,7 +622,8 @@ void lowres_correlation(ASPGlobalOptions & opt) {

// Load IP from disk if they exist, or else compute them.
std::string match_filename;
load_or_compute_ip(opt.session->left_cropped_image(), opt.session->right_cropped_image(),
load_or_compute_ip(opt.session->left_cropped_image(),
opt.session->right_cropped_image(),
opt.cam_file1, opt.cam_file2, opt.out_prefix, opt.session,
// Output
match_filename);
Expand Down
54 changes: 27 additions & 27 deletions src/asp/Tools/stereo_pprc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using namespace vw;
using namespace asp;

// Invalidate pixels < threshold
struct MaskAboveThreshold: public ReturnFixedType< PixelMask<uint8> > {
struct MaskAboveThreshold: public ReturnFixedType<PixelMask<uint8>> {
double m_threshold;
MaskAboveThreshold(double threshold): m_threshold(threshold){}
PixelMask<uint8> operator() (PixelGray<float> const& pix) const {
Expand All @@ -51,9 +51,9 @@ struct MaskAboveThreshold: public ReturnFixedType< PixelMask<uint8> > {
};
template <class ImageT>
UnaryPerPixelView<ImageT, MaskAboveThreshold>
inline mask_above_threshold( ImageViewBase<ImageT> const& image, double threshold ) {
return UnaryPerPixelView<ImageT, MaskAboveThreshold>( image.impl(),
MaskAboveThreshold(threshold) );
inline mask_above_threshold(ImageViewBase<ImageT> const& image, double threshold) {
return UnaryPerPixelView<ImageT, MaskAboveThreshold>(image.impl(),
MaskAboveThreshold(threshold));
}

struct BlobHolder {
Expand All @@ -63,16 +63,16 @@ struct BlobHolder {
boost::shared_ptr<vw::BlobIndexThreaded> m_blobPtr;

// Member function which does the hole-filling.
ImageViewRef< PixelMask<uint8> > mask_and_fill_holes( ImageViewRef< PixelGray<float> > const& img,
double threshold );
ImageViewRef<PixelMask<uint8>>
mask_and_fill_holes(ImageViewRef<PixelGray<float>> const& img, double threshold);
};

/// Create the mask of pixels above threshold. Fix any holes in it.
ImageViewRef< PixelMask<uint8> >
BlobHolder::mask_and_fill_holes( ImageViewRef< PixelGray<float> > const& img,
ImageViewRef<PixelMask<uint8>>
BlobHolder::mask_and_fill_holes( ImageViewRef<PixelGray<float>> const& img,
double threshold ){

ImageViewRef< PixelMask<uint8> > thresh_mask = mask_above_threshold(img, threshold);
ImageViewRef<PixelMask<uint8>> thresh_mask = mask_above_threshold(img, threshold);
int max_area = 0; // fill arbitrarily big holes
bool use_grassfire = false; // fill with default value
PixelMask<uint8> default_inpaint_val = uint8(255);
Expand Down Expand Up @@ -141,7 +141,8 @@ void stereo_preprocessing(bool adjust_left_image_size, ASPGlobalOptions& opt) {
// It could be made to work, but it is an obscure scenario not
// worth testing.
if (skip_img_norm && opt.session->do_bathymetry())
vw_throw( ArgumentErr() << "\nCannot do bathymery when skipping image normalization.\n");
vw_throw( ArgumentErr()
<< "\nCannot do bathymetry when skipping image normalization.\n");

// Need to also write the transformed bathy masks to disk, those
// will be used in stereo_tri.
Expand All @@ -150,15 +151,15 @@ void stereo_preprocessing(bool adjust_left_image_size, ASPGlobalOptions& opt) {
left_image_file, right_image_file);
else // Perform image normalization
opt.session->preprocessing_hook(adjust_left_image_size,
opt.in_file1, opt.in_file2,
left_image_file, right_image_file);
opt.in_file1, opt.in_file2,
left_image_file, right_image_file);

boost::shared_ptr<DiskImageResource>
left_rsrc (vw::DiskImageResourcePtr(left_image_file)),
right_rsrc(vw::DiskImageResourcePtr(right_image_file));

// Load the normalized images.
DiskImageView<PixelGray<float>> left_image (left_rsrc ),
DiskImageView<PixelGray<float>> left_image (left_rsrc),
right_image(right_rsrc);

// If we crop the images, we must always rebuild the masks
Expand Down Expand Up @@ -187,8 +188,8 @@ void stereo_preprocessing(bool adjust_left_image_size, ASPGlobalOptions& opt) {
rebuild = true;
}else{
vw_log().console_log().rule_set().add_rule(-1,"fileio");
DiskImageView<PixelGray<uint8> > testa(left_mask_file );
DiskImageView<PixelGray<uint8> > testb(right_mask_file);
DiskImageView<PixelGray<uint8>> testa(left_mask_file );
DiskImageView<PixelGray<uint8>> testb(right_mask_file);
vw_settings().reload_config();
}
} catch (vw::IOErr const& e) {
Expand All @@ -208,21 +209,20 @@ void stereo_preprocessing(bool adjust_left_image_size, ASPGlobalOptions& opt) {
bool has_nodata = true;
float output_nodata = -32768.0;


if (!rebuild) {
vw_out() << "\t--> Using cached masks.\n";
}else{

vw_out() << "\t--> Generating image masks... \n";
vw_out() << "\t--> Generating image masks.\n";

Stopwatch sw;
sw.start();

ImageViewRef< PixelMask<uint8> > left_mask
ImageViewRef<PixelMask<uint8>> left_mask
= copy_mask(constant_view(uint8(255),
left_image.cols(), left_image.rows()),
asp::threaded_edge_mask(left_image,0,0,1024));
ImageViewRef< PixelMask<uint8> > right_mask
ImageViewRef<PixelMask<uint8>> right_mask
= copy_mask(constant_view(uint8(255),
right_image.cols(), right_image.rows() ),
asp::threaded_edge_mask(right_image,0,0,1024));
Expand Down Expand Up @@ -262,7 +262,7 @@ void stereo_preprocessing(bool adjust_left_image_size, ASPGlobalOptions& opt) {
}
if (!std::isnan(nodata_fraction)){
// Declare a fixed proportion of low-value pixels to be no-data.
math::CDFAccumulator< PixelGray<float> > left_cdf (1024, 1024),
math::CDFAccumulator<PixelGray<float>> left_cdf (1024, 1024),
right_cdf(1024, 1024);
for_each_pixel(left_image, left_cdf );
for_each_pixel(right_image, right_cdf);
Expand All @@ -274,9 +274,9 @@ void stereo_preprocessing(bool adjust_left_image_size, ASPGlobalOptions& opt) {
BlobHolder LB, RB;
// TODO(oalexan1): Wipe this code.
if ( !std::isnan(left_threshold) && !std::isnan(right_threshold) ){
ImageViewRef< PixelMask<uint8> > left_thresh_mask
ImageViewRef<PixelMask<uint8>> left_thresh_mask
= LB.mask_and_fill_holes(left_image, left_threshold);
ImageViewRef< PixelMask<uint8> > right_thresh_mask
ImageViewRef<PixelMask<uint8>> right_thresh_mask
= RB.mask_and_fill_holes(right_image, right_threshold);
left_mask = intersect_mask(left_mask, left_thresh_mask );
right_mask = intersect_mask(right_mask, right_thresh_mask);
Expand Down Expand Up @@ -321,14 +321,14 @@ void stereo_preprocessing(bool adjust_left_image_size, ASPGlobalOptions& opt) {
vw_out() << "Writing masks: " << left_mask_file << ' ' << right_mask_file << ".\n";
if (has_left_georef && has_right_georef && !opt.input_dem.empty()){
// Left image mask transformed into right coordinates
ImageViewRef< PixelMask<uint8> > warped_left_mask
ImageViewRef<PixelMask<uint8>> warped_left_mask
= crop(vw::cartography::geo_transform
(left_mask, left_georef, right_georef,
ConstantEdgeExtension(),NearestPixelInterpolation()
),
bounding_box(right_mask));
// Right image mask transformed into left coordinates
ImageViewRef< PixelMask<uint8> > warped_right_mask
ImageViewRef<PixelMask<uint8>> warped_right_mask
= crop(vw::cartography::geo_transform
(right_mask, right_georef, left_georef,
ConstantEdgeExtension(), NearestPixelInterpolation()
Expand Down Expand Up @@ -387,8 +387,8 @@ void stereo_preprocessing(bool adjust_left_image_size, ASPGlobalOptions& opt) {
rebuild = true;
}else{
// This confusing try catch is to see if the subsampled images actually have content.
DiskImageView<PixelGray<float> > testl (lsub );
DiskImageView<PixelGray<float> > testr (rsub );
DiskImageView<PixelGray<float>> testl (lsub );
DiskImageView<PixelGray<float>> testr (rsub );
DiskImageView<uint8> testlm(lmsub);
DiskImageView<uint8> testrm(rmsub);
vw_out() << "\t--> Using cached subsampled images.\n";
Expand Down Expand Up @@ -523,7 +523,7 @@ void stereo_preprocessing(bool adjust_left_image_size, ASPGlobalOptions& opt) {

ImageViewRef<PixelMask<PixelGray<float>>> left_masked_image
= create_mask_less_or_equal(left_image, left_no_data_value);
ImageViewRef< PixelMask<PixelGray<float>>> right_masked_image
ImageViewRef<PixelMask<PixelGray<float>>> right_masked_image
= create_mask_less_or_equal(right_image, right_no_data_value);

Vector6f left_stats = gather_stats(pixel_cast<PixelMask<float>>(left_masked_image),
Expand Down

0 comments on commit ff09d53

Please sign in to comment.