Patch Detail
Show a patch.
GET /api/patches/22632/?format=api
{ "id": 22632, "url": "https://patchwork.libcamera.org/api/patches/22632/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22632/", "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-18-stefan.klug@ideasonboard.com>", "date": "2025-01-23T11:41:07", "name": "[v2,17/17] libipa: awb_bayes: Change the probabilities from log space into linear space", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "d525e58bbacd62b9c472b85c5b64a9382b10324b", "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/22632/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/22632/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22632/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 9DA89C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Jan 2025 11:43:04 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 36A7368580;\n\tThu, 23 Jan 2025 12:43:04 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3929168579\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jan 2025 12:43:02 +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 B752A1189;\n\tThu, 23 Jan 2025 12:41:58 +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=\"ZKdaoF8t\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1737632518;\n\tbh=sXB+CAsjYxy3i+h3ne6gPXoBMck5zTv5VhZL2vG13Js=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ZKdaoF8tjaLtd46fHt4dV4lblXGn0cS/QKd9HWap6s3h+BXbAOWP8P9rbMkTo/lTY\n\t0v7yuIthLH1NKcckDXTaEOb4aBRxHzCTbgUGGxgdwJyDUeQ1rnm1yzJ0P825te5aPE\n\thK/BX4ZDtY52MerFn3QMQsZIY7G0vaDl9bhq4CeA=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>", "Subject": "[PATCH v2 17/17] libipa: awb_bayes: Change the probabilities from\n\tlog space into linear space", "Date": "Thu, 23 Jan 2025 12:41:07 +0100", "Message-ID": "<20250123114204.79321-18-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": "The original code used to specify the probabilities in log space and\nscaled for the RaspberryPi hardware with 192 AWB measurement points.\nThis is reasonable as the whole algorithm makes use of unitless numbers\nto prefer some colour temperatures based on a lux level. These numbers\nare then hand tuned with the specific device in mind.\n\nThis has two shortcomings:\n\n1. The linear interpolation of PWLs in log space is mathematically\n incorrect. The outcome might still be ok, as both spaces (log and\nlinear) are monotonic, but it is still not \"right\".\n\n2. Having unitless numbers gets more error prone when we try to\n harmonize the behavior over multiple platforms.\n\nChange the algorithm to interpret the numbers as being in linear space.\nThis makes the interpolation mathematically correct at the expense of a\nfew log operations.\n\nTo account for that change, update the numbers in the tuning example\nfile with the linear counterparts scaled to one AWB zone measurement.\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.cpp | 5 +++--\n src/ipa/libipa/awb_bayes.cpp | 8 ++++++--\n utils/tuning/config-example.yaml | 12 ++++++------\n 3 files changed, 15 insertions(+), 10 deletions(-)", "diff": "diff --git a/src/ipa/libipa/awb.cpp b/src/ipa/libipa/awb.cpp\nindex 62b69dd96238..6157bd436183 100644\n--- a/src/ipa/libipa/awb.cpp\n+++ b/src/ipa/libipa/awb.cpp\n@@ -57,8 +57,9 @@ namespace ipa {\n * applied. To keep the actual implementations computationally inexpensive,\n * the squared colour error shall be returned.\n *\n- * If the awb statistics provide multiple zones, the sum over all zones needs to\n- * calculated.\n+ * If the awb statistics provide multiple zones, the average of the individual\n+ * squared errors shall be returned. Averaging/normalizing is necessary so that\n+ * the numeric dimensions are the same on all hardware platforms.\n *\n * \\return The computed error value\n */\ndiff --git a/src/ipa/libipa/awb_bayes.cpp b/src/ipa/libipa/awb_bayes.cpp\nindex 6b88aebeffb5..5f43421e14c7 100644\n--- a/src/ipa/libipa/awb_bayes.cpp\n+++ b/src/ipa/libipa/awb_bayes.cpp\n@@ -235,6 +235,10 @@ int AwbBayes::readPriors(const YamlObject &tuningData)\n \n \t\tauto &pwl = priors[lux];\n \t\tfor (const auto &[ct, prob] : ctToProbability) {\n+\t\t\tif (prob < 1e-6) {\n+\t\t\t\tLOG(Awb, Error) << \"Prior probability must be larger than 1e-6\";\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n \t\t\tpwl.append(ct, prob);\n \t\t}\n \t}\n@@ -324,7 +328,7 @@ double AwbBayes::coarseSearch(const ipa::Pwl &prior, const AwbStats &stats) cons\n \t\tdouble b = ctB_.eval(t, &spanB);\n \t\tRGB<double> gains({ 1 / r, 1.0, 1 / b });\n \t\tdouble delta2Sum = stats.computeColourError(gains);\n-\t\tdouble priorLogLikelihood = prior.eval(prior.domain().clamp(t));\n+\t\tdouble priorLogLikelihood = log(prior.eval(prior.domain().clamp(t)));\n \t\tdouble finalLogLikelihood = delta2Sum - priorLogLikelihood;\n \n \t\terrorLimits.record(delta2Sum);\n@@ -407,7 +411,7 @@ void AwbBayes::fineSearch(double &t, double &r, double &b, ipa::Pwl const &prior\n \tfor (int i = -nsteps; i <= nsteps; i++) {\n \t\tdouble tTest = t + i * step;\n \t\tdouble priorLogLikelihood =\n-\t\t\tprior.eval(prior.domain().clamp(tTest));\n+\t\t\tlog(prior.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) } };\ndiff --git a/utils/tuning/config-example.yaml b/utils/tuning/config-example.yaml\nindex 1bbb275778dc..5593eaef809e 100644\n--- a/utils/tuning/config-example.yaml\n+++ b/utils/tuning/config-example.yaml\n@@ -7,21 +7,21 @@ general:\n awb:\n # Algorithm can either be 'grey' or 'bayes'\n algorithm: bayes\n- # Priors is only used for the bayes algorithm. They are defined in\n- # logarithmic space. A good staring point is:\n+ # Priors is only used for the bayes algorithm. They are defined in linear\n+ # space. A good staring point is:\n # - lux: 0\n # ct: [ 2000, 3000, 13000 ]\n- # probability: [ 1.0, 0.0, 0.0 ]\n+ # probability: [ 1.005, 1.0, 1.0 ]\n # - lux: 800\n # ct: [ 2000, 6000, 13000 ]\n- # probability: [ 0.0, 2.0, 2.0 ]\n+ # probability: [ 1.0, 1.01, 1.01 ]\n # - lux: 1500\n # ct: [ 2000, 4000, 6000, 6500, 7000, 13000 ]\n- # probability: [ 0.0, 1.0, 6.0, 7.0, 1.0, 1.0 ]\n+ # probability: [ 1.0, 1.005, 1.032, 1.037, 1.01, 1.01 ]\n priors:\n - lux: 0\n ct: [ 2000, 13000 ]\n- probability: [ 0.0, 0.0 ]\n+ probability: [ 1.0, 1.0 ]\n AwbMode:\n AwbAuto:\n lo: 2500\n", "prefixes": [ "v2", "17/17" ] }