Show a patch.

GET /api/patches/22630/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 22630,
    "url": "https://patchwork.libcamera.org/api/patches/22630/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22630/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20250123114204.79321-16-stefan.klug@ideasonboard.com>",
    "date": "2025-01-23T11:41:05",
    "name": "[v2,15/17] libipa: awb_bayes: Add logging of value limits",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "25bf22924730b27a4c6f7e157a8ebaa04974ae6e",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/22630/mbox/",
    "series": [
        {
            "id": 4966,
            "url": "https://patchwork.libcamera.org/api/series/4966/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4966",
            "date": "2025-01-23T11:40:50",
            "name": "Add Bayesian AWB algorithm to libipa and rkisp1",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4966/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/22630/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22630/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id ED68FC3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Jan 2025 11:42:57 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9119D6857B;\n\tThu, 23 Jan 2025 12:42:57 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 97E0F68571\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jan 2025 12:42:56 +0100 (CET)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:c0a:33cd:b453:5d3f])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1EFD51081;\n\tThu, 23 Jan 2025 12:41:52 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"tMR9Y+sF\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1737632513;\n\tbh=ZBRMCzJ/sOPnGNweO3iQwZ0j1XClUyiV4lpea0UQpgQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=tMR9Y+sFq8Spt2zbQdfy82xwfqOtMFHQcdg7dHR1xWCOoqjEyczcKyKu4FH9/xU6/\n\tO7uSxUQXZgBMhKrsv/f0ERyACZIwZ0kLyRA3CEwABwwGdSSa2AGROZhtnmUTeQwUID\n\tXKcN7YZPE82kzyeagBKYM133xr/lMlBQlbmDeL7Y=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "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",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "When tuning the AWB algorithm it is more helpful to get a feeling for the\nvalue ranges than to get verbose output of every single step. Add a\nsmall utility class to track the limits and log them.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\n\nChanges in v2:\n- Added this commit\n---\n src/ipa/libipa/awb_bayes.cpp | 57 ++++++++++++++++++++++++++++++++++--\n 1 file changed, 55 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/src/ipa/libipa/awb_bayes.cpp b/src/ipa/libipa/awb_bayes.cpp\nindex 8ab6ed661a3e..aaa8c7a663ad 100644\n--- a/src/ipa/libipa/awb_bayes.cpp\n+++ b/src/ipa/libipa/awb_bayes.cpp\n@@ -50,6 +50,44 @@ namespace libcamera {\n \n LOG_DECLARE_CATEGORY(Awb)\n \n+namespace {\n+\n+template<typename T>\n+class LimitsRecorder\n+{\n+public:\n+\tLimitsRecorder()\n+\t\t: min_(std::numeric_limits<T>::max()),\n+\t\t  max_(std::numeric_limits<T>::min())\n+\t{\n+\t}\n+\n+\tvoid record(const T& value)\n+\t{\n+\t\tmin_ = std::min(min_, value);\n+\t\tmax_ = std::max(max_, value);\n+\t}\n+\n+\tconst T& min() const { return min_; }\n+\tconst T& max() const { return max_; }\n+private:\n+\tT min_;\n+\tT max_;\n+};\n+\n+\n+\n+#ifndef __DOXYGEN__\n+template<typename T>\n+std::ostream &operator<<(std::ostream &out, const LimitsRecorder<T> &v)\n+{\n+\tout << \"[ \" << v.min() << \", \" << v.max() << \" ]\";\n+\treturn out;\n+}\n+#endif\n+\n+} /* namespace */\n+\n namespace ipa {\n \n /**\n@@ -277,6 +315,8 @@ double AwbBayes::coarseSearch(const ipa::Pwl &prior, const AwbStats &stats) cons\n \tdouble t = currentMode_->ctLo;\n \tint spanR = -1;\n \tint spanB = -1;\n+\tLimitsRecorder<double> errorLimits;\n+\tLimitsRecorder<double> priorLogLikelihoodLimits;\n \n \t/* Step down the CT curve evaluating log likelihood. */\n \twhile (true) {\n@@ -287,6 +327,9 @@ double AwbBayes::coarseSearch(const ipa::Pwl &prior, const AwbStats &stats) cons\n \t\tdouble priorLogLikelihood = prior.eval(prior.domain().clamp(t));\n \t\tdouble finalLogLikelihood = delta2Sum - priorLogLikelihood;\n \n+\t\terrorLimits.record(delta2Sum);\n+\t\tpriorLogLikelihoodLimits.record(priorLogLikelihood);\n+\n \t\tLOG(Awb, Debug) << \"Coarse search t: \" << t\n \t\t\t\t<< \" gains: \" << gains\n \t\t\t\t<< \" error: \" << delta2Sum\n@@ -308,7 +351,9 @@ double AwbBayes::coarseSearch(const ipa::Pwl &prior, const AwbStats &stats) cons\n \t}\n \n \tt = points[bestPoint].x();\n-\tLOG(Awb, Debug) << \"Coarse search found CT \" << t;\n+\tLOG(Awb, Debug) << \"Coarse search found CT \" << t\n+\t\t\t<< \" error limits:\" << errorLimits\n+\t\t\t<< \" prior log likelihood limits:\" << priorLogLikelihoodLimits;\n \n \t/*\n \t * We have the best point of the search, but refine it with a quadratic\n@@ -352,6 +397,9 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior\n \tPwl::Point bestRB;\n \tdouble transverseRange = transverseNeg_ + transversePos_;\n \tconst int maxNumDeltas = 12;\n+\tLimitsRecorder<double> errorLimits;\n+\tLimitsRecorder<double> priorLogLikelihoodLimits;\n+\n \n \t/* a transverse step approximately every 0.01 r/b units */\n \tint numDeltas = floor(transverseRange * 100 + 0.5) + 1;\n@@ -366,6 +414,7 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior\n \t\tdouble tTest = t + i * step;\n \t\tdouble priorLogLikelihood =\n \t\t\tprior.eval(prior.domain().clamp(tTest));\n+\t\tpriorLogLikelihoodLimits.record(priorLogLikelihood);\n \t\tPwl::Point rbStart{ { ctR_.eval(tTest, &spanR),\n \t\t\t\t      ctB_.eval(tTest, &spanB) } };\n \t\tPwl::Point samples[maxNumDeltas];\n@@ -384,6 +433,7 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior\n \t\t\tPwl::Point rbTest = rbStart + transverse * p.x();\n \t\t\tRGB<double> gains({ 1 / rbTest[0], 1.0, 1 / rbTest[1] });\n \t\t\tdouble delta2Sum = stats.computeColourError(gains);\n+\t\t\terrorLimits.record(delta2Sum);\n \t\t\tp.y() = delta2Sum - priorLogLikelihood;\n \n \t\t\tif (p.y() < samples[bestPoint].y())\n@@ -401,6 +451,7 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior\n \t\tPwl::Point rbTest = rbStart + transverse * bestOffset;\n \t\tRGB<double> gains({ 1 / rbTest[0], 1.0, 1 / rbTest[1] });\n \t\tdouble delta2Sum = stats.computeColourError(gains);\n+\t\terrorLimits.record(delta2Sum);\n \t\tdouble finalLogLikelihood = delta2Sum - priorLogLikelihood;\n \t\tLOG(Awb, Debug)\n \t\t\t<< \"Fine search t: \" << tTest\n@@ -421,7 +472,9 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior\n \tr = bestRB[0];\n \tb = bestRB[1];\n \tLOG(Awb, Debug)\n-\t\t<< \"Fine search found t \" << t << \" r \" << r << \" b \" << b;\n+\t\t<< \"Fine search found t \" << t << \" r \" << r << \" b \" << b\n+\t\t<< \" error limits: \" << errorLimits\n+\t\t<< \" prior log likelihood limits: \" << priorLogLikelihoodLimits;\n }\n \n /**\n",
    "prefixes": [
        "v2",
        "15/17"
    ]
}