Skip to content

Commit e52b4e5

Browse files
authored
Merge pull request #1688 from alicevision/fix/sfmStats
[sfm] statistics: fix statistics to avoid troubles in particular cases
2 parents d6a8544 + 3b164fa commit e52b4e5

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/aliceVision/sfm/sfmStatistics.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ void computeResidualsHistogram(const sfmData::SfMData& sfmData,
6464

6565
if (outHistogram)
6666
{
67-
*outHistogram = utils::Histogram<double>(0.0, std::ceil(outStats.max), std::ceil(outStats.max) * 2);
67+
// clamp the max residu:
68+
// - avoid errors in case of nonsense values
69+
// - focus on the important residu, the small ones
70+
const size_t maxValue = clamp(size_t(std::ceil(outStats.max)), size_t(1), size_t(30));
71+
*outHistogram = utils::Histogram<double>(0.0, maxValue, maxValue * 5);
6872
outHistogram->Add(vecResiduals.begin(), vecResiduals.end());
6973
}
7074
}
@@ -122,7 +126,9 @@ void computeObservationsLengthsHistogram(const sfmData::SfMData& sfmData,
122126

123127
if (outHistogram)
124128
{
125-
*outHistogram = utils::Histogram<double>(outStats.min, outStats.max + 1, outStats.max - outStats.min + 1);
129+
// clamp the max to avoid errors in case of nonsense values
130+
const size_t maxValue = clamp(size_t(std::ceil(outStats.max) + 1), size_t(1), size_t(1000));
131+
*outHistogram = utils::Histogram<double>(0.0, maxValue, maxValue);
126132
outHistogram->Add(nbObservations.begin(), nbObservations.end());
127133
}
128134
}
@@ -166,8 +172,8 @@ void computeLandmarksPerViewHistogram(const sfmData::SfMData& sfmData, BoxStats<
166172

167173
if (outHistogram)
168174
{
169-
//*outHistogram = Histogram<double>(0, sfmData.getViews().size(), sfmData.getViews().size());
170-
*outHistogram = utils::Histogram<double>(outStats.min, (outStats.max + 1), 10);
175+
const size_t nBins = 50;
176+
*outHistogram = utils::Histogram<double>(outStats.min, (outStats.max + 1), nBins);
171177
outHistogram->Add(nbLandmarksPerViewVec.begin(), nbLandmarksPerViewVec.end());
172178
}
173179
}
@@ -304,6 +310,7 @@ void computeScaleHistogram(const sfmData::SfMData& sfmData,
304310
if (outHistogram)
305311
{
306312
size_t maxValue = std::ceil(outStats.max);
313+
maxValue = clamp(maxValue, size_t(1), size_t(100)); // clamp max value in case of nonsense value
307314
*outHistogram = utils::Histogram<double>(0.0, double(maxValue), maxValue + 1);
308315
outHistogram->Add(vecScaleObservations.begin(), vecScaleObservations.end());
309316
}
@@ -359,9 +366,6 @@ void computeResidualsPerView(const sfmData::SfMData& sfmData,
359366
continue;
360367
const std::vector<double>& residuals = it->second;
361368
BoxStats<double> residualStats(residuals.begin(), residuals.end());
362-
utils::Histogram<double> residual_histogram =
363-
utils::Histogram<double>(residualStats.min, residualStats.max + 1, residualStats.max - residualStats.min + 1);
364-
residual_histogram.Add(residuals.begin(), residuals.end());
365369

366370
nbResidualsPerViewMin[viewIdx] = residualStats.min;
367371
nbResidualsPerViewMax[viewIdx] = residualStats.max;
@@ -414,9 +418,6 @@ void computeObservationsLengthsPerView(const sfmData::SfMData& sfmData,
414418
const IndexT viewId = viewKeys[viewIdx];
415419
const std::vector<int>& nbObservations = observationLengthsPerView[viewId];
416420
BoxStats<double> observationsLengthsStats(nbObservations.begin(), nbObservations.end());
417-
utils::Histogram<double> observationsLengthsHistogram(
418-
observationsLengthsStats.min, observationsLengthsStats.max + 1, observationsLengthsStats.max - observationsLengthsStats.min + 1);
419-
observationsLengthsHistogram.Add(nbObservations.begin(), nbObservations.end());
420421

421422
nbObservationsLengthsPerViewMin[viewIdx] = observationsLengthsStats.min;
422423
nbObservationsLengthsPerViewMax[viewIdx] = observationsLengthsStats.max;

0 commit comments

Comments
 (0)