Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(trivial) Extract removePoorlyOverlappingImagePairs() #1288

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/aliceVision/matchingImageCollection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(matching_collection_images_files_sources
matchingCommon.cpp
ImageCollectionMatcher_generic.cpp
ImageCollectionMatcher_cascadeHashing.cpp
GeometricFilter.cpp
GeometricFilterMatrix_HGrowing.cpp
geometricFilterUtils.cpp
pairBuilder.cpp
Expand Down
36 changes: 36 additions & 0 deletions src/aliceVision/matchingImageCollection/GeometricFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This file is part of the AliceVision project.
// Copyright (c) 2022 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include "GeometricFilter.hpp"

namespace aliceVision {
namespace matchingImageCollection {

void removePoorlyOverlappingImagePairs(PairwiseMatches& geometricMatches,
const PairwiseMatches& putativeMatches,
float minimumRatio,
std::size_t minimumGeometricCount)
{
std::vector<PairwiseMatches::key_type> toRemoveVec;
for (const auto& match : geometricMatches)
{
const size_t photometricCount = putativeMatches.find(match.first)->second.getNbAllMatches();
const size_t geometricCount = match.second.getNbAllMatches();
const float ratio = geometricCount / (float)photometricCount;
if (geometricCount < minimumGeometricCount || ratio < minimumRatio) {
toRemoveVec.push_back(match.first); // the image pair will be removed
}
}

// remove discarded pairs
for (const auto& pair : toRemoveVec)
{
geometricMatches.erase(pair);
}
}

} // namespace matchingImageCollection
} // namespace aliceVision
16 changes: 15 additions & 1 deletion src/aliceVision/matchingImageCollection/GeometricFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#include <aliceVision/matchingImageCollection/GeometricFilterMatrix.hpp>
#include <aliceVision/system/ProgressDisplay.hpp>

#include <vector>
#include <map>
#include <random>
#include <vector>

namespace aliceVision {
namespace matchingImageCollection {
Expand Down Expand Up @@ -90,6 +91,19 @@ void robustModelEstimation(
}
}

/**
* @brief removePoorlyOverlappingImagePairs Removes image pairs from the given list of geometric
* matches that have poor overlap according to the supplied criteria.
* @param[in,out] geometricMatches List of geometric matches to clean up
* @param putativeMatches List of putative matches
* @param minimumRatio Minimum ratio of geometric to putative matches for image pair
* @param minimumCount Minimum count of geometric matches for image pair
*/
void removePoorlyOverlappingImagePairs(PairwiseMatches& geometricMatches,
const PairwiseMatches& putativeMatches,
float minimumRatio,
std::size_t minimumGeometricCount);

} // namespace matchingImageCollection
} // namespace aliceVision

Expand Down
17 changes: 1 addition & 16 deletions src/software/pipeline/main_featureMatching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,22 +506,7 @@ int aliceVision_main(int argc, char **argv)
randomNumberGenerator,
guidedMatching);

// perform an additional check to remove pairs with poor overlap
std::vector<PairwiseMatches::key_type> toRemoveVec;
for(PairwiseMatches::const_iterator iterMap = geometricMatches.begin();
iterMap != geometricMatches.end(); ++iterMap)
{
const size_t putativePhotometricCount = mapPutativesMatches.find(iterMap->first)->second.getNbAllMatches();
const size_t putativeGeometricCount = iterMap->second.getNbAllMatches();
const float ratio = putativeGeometricCount / (float)putativePhotometricCount;
if (putativeGeometricCount < 50 || ratio < .3f)
toRemoveVec.push_back(iterMap->first); // the image pair will be removed
}

// remove discarded pairs
for(std::vector<PairwiseMatches::key_type>::const_iterator iter = toRemoveVec.begin();
iter != toRemoveVec.end(); ++iter)
geometricMatches.erase(*iter);
removePoorlyOverlappingImagePairs(geometricMatches, mapPutativesMatches, 0.3f, 50);
}
break;

Expand Down