Skip to content

Commit

Permalink
[sfm] statistics: fix statistics to avoid troubles in particular cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiencastan committed Mar 24, 2024
1 parent eb82aa7 commit bc8a1c4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/aliceVision/sfm/sfmStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ void computeResidualsHistogram(const sfmData::SfMData& sfmData,

if (outHistogram)
{
*outHistogram = utils::Histogram<double>(0.0, std::ceil(outStats.max), std::ceil(outStats.max) * 2);
// clamp the max residu:
// - avoid errors in case of nonsense values
// - focus on the important residu, the small ones
const size_t maxValue = std::min(size_t(std::ceil(outStats.max)), size_t(30));
*outHistogram = utils::Histogram<double>(0.0, maxValue, maxValue * 5);
outHistogram->Add(vecResiduals.begin(), vecResiduals.end());
}
}
Expand Down Expand Up @@ -122,7 +126,9 @@ void computeObservationsLengthsHistogram(const sfmData::SfMData& sfmData,

if (outHistogram)
{
*outHistogram = utils::Histogram<double>(outStats.min, outStats.max + 1, outStats.max - outStats.min + 1);
// clamp the max to avoid errors in case of nonsense values
const size_t maxValue = std::min(size_t(std::ceil(outStats.max) + 1), size_t(1000));
*outHistogram = utils::Histogram<double>(0.0, maxValue, maxValue);
outHistogram->Add(nbObservations.begin(), nbObservations.end());
}
}
Expand Down Expand Up @@ -166,8 +172,7 @@ void computeLandmarksPerViewHistogram(const sfmData::SfMData& sfmData, BoxStats<

if (outHistogram)
{
//*outHistogram = Histogram<double>(0, sfmData.getViews().size(), sfmData.getViews().size());
*outHistogram = utils::Histogram<double>(outStats.min, (outStats.max + 1), 10);
*outHistogram = utils::Histogram<double>(outStats.min, (outStats.max + 1), 50);
outHistogram->Add(nbLandmarksPerViewVec.begin(), nbLandmarksPerViewVec.end());
}
}
Expand Down Expand Up @@ -304,6 +309,7 @@ void computeScaleHistogram(const sfmData::SfMData& sfmData,
if (outHistogram)
{
size_t maxValue = std::ceil(outStats.max);
maxValue = std::min(maxValue, size_t(100)); // clamp max value in case of nonsense value
*outHistogram = utils::Histogram<double>(0.0, double(maxValue), maxValue + 1);
outHistogram->Add(vecScaleObservations.begin(), vecScaleObservations.end());
}
Expand Down

0 comments on commit bc8a1c4

Please sign in to comment.