Show a patch.

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

{
    "id": 22623,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/22623/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22623/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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-9-stefan.klug@ideasonboard.com>",
    "date": "2025-01-23T11:40:58",
    "name": "[v2,08/17] libtuning: module: awb: Add bayes AWB support",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "ba0e745ebcd83e537ab3256335c40f3935c3f474",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/22623/mbox/",
    "series": [
        {
            "id": 4966,
            "url": "https://patchwork.libcamera.org/api/1.1/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/22623/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22623/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 91FADC3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Jan 2025 11:42:38 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E3CD36856F;\n\tThu, 23 Jan 2025 12:42:37 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D5C568568\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jan 2025 12:42:34 +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 B28D519AE;\n\tThu, 23 Jan 2025 12:41:30 +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=\"Xh3SaMZ7\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1737632490;\n\tbh=Os5HO9CiOcoIJ6ahMj8NPEbXy4f0p6+vj8Ab6atxdGA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Xh3SaMZ76i81Ym/UI979pLCn5praX4sj6G07aoXwufQ+eAbLriUvofM/C+5Cmty3x\n\tW4G3tlnb5PN1+mZFpncqW2BF3qvYliU0QTKvbT/4yr0auHBtP7Y+pIVj4cvCtshsX7\n\t0ov1Ljg6mR1YL1a8nsxaIu6EJvjHOlUKrGvwKzFA=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>",
        "Subject": "[PATCH v2 08/17] libtuning: module: awb: Add bayes AWB support",
        "Date": "Thu, 23 Jan 2025 12:40:58 +0100",
        "Message-ID": "<20250123114204.79321-9-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": "To support the bayesian AWB algorithm in libtuning, the necessary data\nneeds to be collected and written to the tuning file.\n\nExtend libtuning to calculate and output that additional data.\n\nPrior probabilities and AwbModes are manually specified and not\ncalculated in the tuning process. Add sample values from the RaspberryPi\ntuning files to the example config file.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\n\nChanges in v2:\n- Collected tags\n- Fixed missing space\n- Reworked commit message\n- Add example prior probabilities from RaspberryPi\n---\n utils/tuning/config-example.yaml             | 44 +++++++++++++++++++-\n utils/tuning/libtuning/modules/awb/awb.py    | 16 ++++---\n utils/tuning/libtuning/modules/awb/rkisp1.py | 21 +++++++---\n 3 files changed, 68 insertions(+), 13 deletions(-)",
    "diff": "diff --git a/utils/tuning/config-example.yaml b/utils/tuning/config-example.yaml\nindex 1b7f52cd2fff..1bbb275778dc 100644\n--- a/utils/tuning/config-example.yaml\n+++ b/utils/tuning/config-example.yaml\n@@ -5,7 +5,49 @@ general:\n     do_alsc_colour: 1\n     luminance_strength: 0.5\n   awb:\n-    greyworld: 0\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+    # - lux: 0\n+    #   ct: [ 2000, 3000, 13000 ]\n+    #   probability: [ 1.0, 0.0, 0.0 ]\n+    # - lux: 800\n+    #   ct: [ 2000, 6000, 13000 ]\n+    #   probability: [ 0.0, 2.0, 2.0 ]\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+    priors:\n+      - lux: 0\n+        ct: [ 2000, 13000 ]\n+        probability: [ 0.0, 0.0 ]\n+    AwbMode:\n+      AwbAuto:\n+        lo: 2500\n+        hi: 8000\n+      AwbIncandescent:\n+        lo: 2500\n+        hi: 3000\n+      AwbTungsten:\n+        lo: 3000\n+        hi: 3500\n+      AwbFluorescent:\n+        lo: 4000\n+        hi: 4700\n+      AwbIndoor:\n+        lo: 3000\n+        hi: 5000\n+      AwbDaylight:\n+        lo: 5500\n+        hi: 6500\n+      AwbCloudy:\n+        lo: 6500\n+        hi: 8000\n+      # One custom mode can be defined if needed\n+      #AwbCustom:\n+      #  lo: 2000\n+      #  hi: 1300\n   macbeth:\n     small: 1\n     show: 0\ndiff --git a/utils/tuning/libtuning/modules/awb/awb.py b/utils/tuning/libtuning/modules/awb/awb.py\nindex c154cf3b8609..0dc4f59dcb26 100644\n--- a/utils/tuning/libtuning/modules/awb/awb.py\n+++ b/utils/tuning/libtuning/modules/awb/awb.py\n@@ -27,10 +27,14 @@ class AWB(Module):\n \n         imgs = [img for img in images if img.macbeth is not None]\n \n-        gains, _, _ = awb(imgs, None, None, False)\n-        gains = np.reshape(gains, (-1, 3))\n+        ct_curve, transverse_pos, transverse_neg = awb(imgs, None, None, False)\n+        ct_curve = np.reshape(ct_curve, (-1, 3))\n+        gains = [{\n+            'ct': int(v[0]),\n+            'gains': [float(1.0 / v[1]), float(1.0 / v[2])]\n+        } for v in ct_curve]\n+\n+        return {'colourGains': gains,\n+                'transversePos': transverse_pos,\n+                'transverseNeg': transverse_neg}\n \n-        return [{\n-                    'ct': int(v[0]),\n-                    'gains': [float(1.0 / v[1]), float(1.0 / v[2])]\n-                } for v in gains]\ndiff --git a/utils/tuning/libtuning/modules/awb/rkisp1.py b/utils/tuning/libtuning/modules/awb/rkisp1.py\nindex 0c95843b83d3..d562d26eb8cc 100644\n--- a/utils/tuning/libtuning/modules/awb/rkisp1.py\n+++ b/utils/tuning/libtuning/modules/awb/rkisp1.py\n@@ -6,9 +6,6 @@\n \n from .awb import AWB\n \n-import libtuning as lt\n-\n-\n class AWBRkISP1(AWB):\n     hr_name = 'AWB (RkISP1)'\n     out_name = 'Awb'\n@@ -20,8 +17,20 @@ class AWBRkISP1(AWB):\n         return True\n \n     def process(self, config: dict, images: list, outputs: dict) -> dict:\n-        output = {}\n-\n-        output['colourGains'] = self.do_calculation(images)\n+        if not 'awb' in config['general']:\n+            raise ValueError('AWB configuration missing')\n+        awb_config = config['general']['awb']\n+        algorithm = awb_config['algorithm']\n+\n+        output = {'algorithm': algorithm}\n+        data = self.do_calculation(images)\n+        if algorithm == 'grey':\n+            output['colourGains'] = data['colourGains']\n+        elif algorithm == 'bayes':\n+            output['AwbMode'] = awb_config['AwbMode']\n+            output['priors'] = awb_config['priors']\n+            output.update(data)\n+        else:\n+            raise ValueError(f\"Unknown AWB algorithm {output['algorithm']}\")\n \n         return output\n",
    "prefixes": [
        "v2",
        "08/17"
    ]
}