Skip to content

Apply distance weighting for observations#2123

Open
servantftransperfect wants to merge 1 commit intodevelopfrom
dev/residualNormalization
Open

Apply distance weighting for observations#2123
servantftransperfect wants to merge 1 commit intodevelopfrom
dev/residualNormalization

Conversation

@servantftransperfect
Copy link
Copy Markdown
Contributor

@servantftransperfect servantftransperfect commented May 4, 2026

This pull request introduces an option to enable per-observation weighting in the SfM expanding pipeline to reduce the impact of high-density regions in images. The main changes add a new parameter and command-line option, implement the observation weighting algorithm, and propagate the weights through the bundle adjustment process. This helps to improve the robustness of reconstruction in scenes with uneven feature distributions.

Observation Weighting Feature:

  • Added a new parameter enableObservationsWeighting to the SfMExpanding node and exposed it as a command-line option in main_sfmExpanding.cpp to allow users to enable or disable observation weighting. [1] [2] [3]
  • Implemented the observation weighting algorithm in the new files DistanceWeighting.cpp and DistanceWeighting.hpp, which computes weights for each observation based on local 2D feature density using k-NN and normalizes them. [1] [2]
  • Integrated the weighting algorithm into the SfM pipeline by calling it from SfmBundle when enabled, and added support for toggling this feature via the SfmBundle API and internal state. [1] [2] [3] [4] [5]

Propagation and Usage of Weights:

  • Extended the Observation class to store and access a per-feature weight, defaulting to 1.0. [1] [2]
  • Modified the bundle adjustment cost function (intrinsicsProject.hpp) to scale residuals and Jacobians by the square root of the observation weight, ensuring that weighted observations influence optimization appropriately.

Dependencies and Build System:

  • Added DistanceWeighting.cpp to the CMake build and linked the nanoflann library, updating the nanoflann dependency version for k-NN search. [1] [2] [3]

These changes collectively add robust support for observation weighting in the SfM expanding pipeline, improving results in challenging scenarios with non-uniform feature distributions.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an optional “distance-based observation weighting” mechanism for the SfM Expanding pipeline, intended to reduce the influence of dense 2D feature regions during bundle adjustment by assigning per-observation weights derived from local k-NN spacing in image space.

Changes:

  • Add a new per-observation weight field to sfmData::Observation and apply it inside projection residual computation.
  • Add a new distance-based weighting pass (DistanceWeighting.*) that computes weights per view using nanoflann k-NN search.
  • Expose a new CLI/Meshroom parameter (enableObservationsWeighting) to enable/disable the weighting in SfmBundle during iteration initialization, and link nanoflann into the aliceVision_sfm target.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/software/pipeline/main_sfmExpanding.cpp Adds a CLI switch to enable distance-based observation weighting in the expanding SfM pipeline.
src/cmake/DependenciesVersions.cmake Updates the pinned nanoflann commit used by the project.
src/aliceVision/sfmData/Observation.hpp Introduces a _weight field with getters/setters (default 1.0).
src/aliceVision/sfm/pipeline/expanding/SfmBundle.hpp Adds a setter to enable/disable observation weighting.
src/aliceVision/sfm/pipeline/expanding/SfmBundle.cpp Runs the weighting pass during initializeIteration() when enabled.
src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.hpp Declares the new weighting routine operating in-place on SfMData observations.
src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp Implements per-view k-NN spacing based weighting using nanoflann and OpenMP.
src/aliceVision/sfm/CMakeLists.txt Adds the new source file and links nanoflann::nanoflann into aliceVision_sfm.
src/aliceVision/sfm/bundle/costfunctions/intrinsicsProject.hpp Applies observation weight to residuals (and corresponding Jacobians) in the projection cost.
meshroom/aliceVision/SfmExpanding.py Exposes the new parameter in Meshroom’s SfM Expanding node.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp Outdated
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp Outdated
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp Outdated
Comment thread src/aliceVision/sfmData/Observation.hpp Outdated
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp Outdated
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp Outdated
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp Outdated
Comment thread src/aliceVision/sfm/bundle/costfunctions/intrinsicsProject.hpp
Comment thread src/aliceVision/sfmData/Observation.hpp Outdated
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +55 to +59
const double weight = _measured.getWeight();

auto test = std::dynamic_pointer_cast<camera::Pinhole>(_intrinsics);

residuals[0] = (pt_est(0) - _measured.getX()) / scale;
residuals[1] = (pt_est(1) - _measured.getY()) / scale;
residuals[0] = weight * (pt_est(0) - _measured.getX()) / scale;
Comment on lines 67 to 69
size_t params_size = _intrinsics->getParametersSize();
double d_res_d_pt_est = 1.0 / scale;
double d_res_d_pt_est = weight / scale;

Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp Outdated
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp
Comment thread src/aliceVision/sfm/pipeline/expanding/DistanceWeighting.cpp
Comment thread src/software/pipeline/main_sfmExpanding.cpp Outdated
Comment thread meshroom/aliceVision/SfmExpanding.py Outdated
Co-authored-by: Copilot <copilot@github.com>
@servantftransperfect servantftransperfect force-pushed the dev/residualNormalization branch from 4f3d66f to 4f8b2ef Compare May 4, 2026 15:17
@servantftransperfect servantftransperfect marked this pull request as ready for review May 4, 2026 15:17
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants