From c2059585f3c7289af000b6d40734b94ece5c083c Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Thu, 23 Jan 2025 12:41:05 +0100 Subject: libipa: awb_bayes: Add logging of value limits When tuning the AWB algorithm it is more helpful to get a feeling for the value ranges than to get verbose output of every single step. Add a small utility class to track the limits and log them. Signed-off-by: Stefan Klug Reviewed-by: Paul Elder Reviewed-by: Daniel Scally --- src/ipa/libipa/awb_bayes.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/src/ipa/libipa/awb_bayes.cpp b/src/ipa/libipa/awb_bayes.cpp index 70727908..fc8502a2 100644 --- a/src/ipa/libipa/awb_bayes.cpp +++ b/src/ipa/libipa/awb_bayes.cpp @@ -50,6 +50,43 @@ namespace libcamera { LOG_DECLARE_CATEGORY(Awb) +namespace { + +template +class LimitsRecorder +{ +public: + LimitsRecorder() + : min_(std::numeric_limits::max()), + max_(std::numeric_limits::min()) + { + } + + void record(const T &value) + { + min_ = std::min(min_, value); + max_ = std::max(max_, value); + } + + const T &min() const { return min_; } + const T &max() const { return max_; } + +private: + T min_; + T max_; +}; + +#ifndef __DOXYGEN__ +template +std::ostream &operator<<(std::ostream &out, const LimitsRecorder &v) +{ + out << "[ " << v.min() << ", " << v.max() << " ]"; + return out; +} +#endif + +} /* namespace */ + namespace ipa { /** @@ -277,6 +314,8 @@ double AwbBayes::coarseSearch(const ipa::Pwl &prior, const AwbStats &stats) cons double t = currentMode_->ctLo; int spanR = -1; int spanB = -1; + LimitsRecorder errorLimits; + LimitsRecorder priorLogLikelihoodLimits; /* Step down the CT curve evaluating log likelihood. */ while (true) { @@ -287,6 +326,9 @@ double AwbBayes::coarseSearch(const ipa::Pwl &prior, const AwbStats &stats) cons double priorLogLikelihood = prior.eval(prior.domain().clamp(t)); double finalLogLikelihood = delta2Sum - priorLogLikelihood; + errorLimits.record(delta2Sum); + priorLogLikelihoodLimits.record(priorLogLikelihood); + LOG(Awb, Debug) << "Coarse search t: " << t << " gains: " << gains << " error: " << delta2Sum @@ -308,7 +350,9 @@ double AwbBayes::coarseSearch(const ipa::Pwl &prior, const AwbStats &stats) cons } t = points[bestPoint].x(); - LOG(Awb, Debug) << "Coarse search found CT " << t; + LOG(Awb, Debug) << "Coarse search found CT " << t + << " error limits:" << errorLimits + << " prior log likelihood limits:" << priorLogLikelihoodLimits; /* * We have the best point of the search, but refine it with a quadratic @@ -352,6 +396,9 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior Pwl::Point bestRB(0); double transverseRange = transverseNeg_ + transversePos_; const int maxNumDeltas = 12; + LimitsRecorder errorLimits; + LimitsRecorder priorLogLikelihoodLimits; + /* a transverse step approximately every 0.01 r/b units */ int numDeltas = floor(transverseRange * 100 + 0.5) + 1; @@ -366,6 +413,7 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior double tTest = t + i * step; double priorLogLikelihood = prior.eval(prior.domain().clamp(tTest)); + priorLogLikelihoodLimits.record(priorLogLikelihood); Pwl::Point rbStart{ { ctR_.eval(tTest, &spanR), ctB_.eval(tTest, &spanB) } }; Pwl::Point samples[maxNumDeltas]; @@ -384,6 +432,7 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior Pwl::Point rbTest = rbStart + transverse * p.x(); RGB gains({ 1 / rbTest[0], 1.0, 1 / rbTest[1] }); double delta2Sum = stats.computeColourError(gains); + errorLimits.record(delta2Sum); p.y() = delta2Sum - priorLogLikelihood; if (p.y() < samples[bestPoint].y()) @@ -401,6 +450,7 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior Pwl::Point rbTest = rbStart + transverse * bestOffset; RGB gains({ 1 / rbTest[0], 1.0, 1 / rbTest[1] }); double delta2Sum = stats.computeColourError(gains); + errorLimits.record(delta2Sum); double finalLogLikelihood = delta2Sum - priorLogLikelihood; LOG(Awb, Debug) << "Fine search t: " << tTest @@ -421,7 +471,9 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior r = bestRB[0]; b = bestRB[1]; LOG(Awb, Debug) - << "Fine search found t " << t << " r " << r << " b " << b; + << "Fine search found t " << t << " r " << r << " b " << b + << " error limits: " << errorLimits + << " prior log likelihood limits: " << priorLogLikelihoodLimits; } /** -- cgit v1.2.1