From patchwork Thu Jan 23 11:41:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22630 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id ED68FC3226 for ; Thu, 23 Jan 2025 11:42:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9119D6857B; Thu, 23 Jan 2025 12:42:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tMR9Y+sF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 97E0F68571 for ; Thu, 23 Jan 2025 12:42:56 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:c0a:33cd:b453:5d3f]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1EFD51081; Thu, 23 Jan 2025 12:41:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1737632513; bh=ZBRMCzJ/sOPnGNweO3iQwZ0j1XClUyiV4lpea0UQpgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tMR9Y+sFq8Spt2zbQdfy82xwfqOtMFHQcdg7dHR1xWCOoqjEyczcKyKu4FH9/xU6/ O7uSxUQXZgBMhKrsv/f0ERyACZIwZ0kLyRA3CEwABwwGdSSa2AGROZhtnmUTeQwUID XKcN7YZPE82kzyeagBKYM133xr/lMlBQlbmDeL7Y= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 15/17] libipa: awb_bayes: Add logging of value limits Date: Thu, 23 Jan 2025 12:41:05 +0100 Message-ID: <20250123114204.79321-16-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250123114204.79321-1-stefan.klug@ideasonboard.com> References: <20250123114204.79321-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- Changes in v2: - Added this commit --- src/ipa/libipa/awb_bayes.cpp | 57 ++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/ipa/libipa/awb_bayes.cpp b/src/ipa/libipa/awb_bayes.cpp index 8ab6ed661a3e..aaa8c7a663ad 100644 --- a/src/ipa/libipa/awb_bayes.cpp +++ b/src/ipa/libipa/awb_bayes.cpp @@ -50,6 +50,44 @@ 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 +315,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 +327,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 +351,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 +397,9 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior Pwl::Point bestRB; 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 +414,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 +433,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 +451,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 +472,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; } /**