Apply distance weighting for observations#2123
Apply distance weighting for observations#2123servantftransperfect wants to merge 1 commit intodevelopfrom
Conversation
There was a problem hiding this comment.
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::Observationand 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 inSfmBundleduring iteration initialization, and linknanoflanninto thealiceVision_sfmtarget.
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.
There was a problem hiding this comment.
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.
37d55b7 to
4f3d66f
Compare
There was a problem hiding this comment.
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.
| 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; |
| size_t params_size = _intrinsics->getParametersSize(); | ||
| double d_res_d_pt_est = 1.0 / scale; | ||
| double d_res_d_pt_est = weight / scale; | ||
|
|
Co-authored-by: Copilot <copilot@github.com>
4f3d66f to
4f8b2ef
Compare
|



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:
enableObservationsWeightingto theSfMExpandingnode and exposed it as a command-line option inmain_sfmExpanding.cppto allow users to enable or disable observation weighting. [1] [2] [3]DistanceWeighting.cppandDistanceWeighting.hpp, which computes weights for each observation based on local 2D feature density using k-NN and normalizes them. [1] [2]SfmBundlewhen enabled, and added support for toggling this feature via theSfmBundleAPI and internal state. [1] [2] [3] [4] [5]Propagation and Usage of Weights:
Observationclass to store and access a per-feature weight, defaulting to 1.0. [1] [2]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:
DistanceWeighting.cppto the CMake build and linked thenanoflannlibrary, 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.