Patch Detail
Show a patch.
GET /api/1.1/patches/22627/?format=api
{ "id": 22627, "url": "https://patchwork.libcamera.org/api/1.1/patches/22627/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22627/", "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-13-stefan.klug@ideasonboard.com>", "date": "2025-01-23T11:41:02", "name": "[v2,12/17] libtuning: Add module for lux calibration", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "507ee47552d4d09720cbeff1bc09af5fe5c07bcc", "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/22627/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/22627/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22627/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 12725C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Jan 2025 11:42:49 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC76768571;\n\tThu, 23 Jan 2025 12:42:48 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 27C9A68571\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jan 2025 12:42:46 +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 A83A41E05;\n\tThu, 23 Jan 2025 12:41:42 +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=\"ZW/2AJ59\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1737632502;\n\tbh=hE1vGg38bFWOkotuhQlyejuYp84mGRWyKxg/1RbB5jI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ZW/2AJ59OOfw35s/jkEDW0Slyq3qQ5gdjoqBQ9jHqLavAHeh2IaK9YobPOeqQhWXa\n\tSpdE8q1EyAhmDYIV9zq30vvpB/If1g1C5X/yUNJPRjDkPiZdRRh7zW2cUYAgyS6aPr\n\t9bPncvX2hOMCMMKcKmtENRDEUSvULRBQOSe0pzy0=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>", "Subject": "[PATCH v2 12/17] libtuning: Add module for lux calibration", "Date": "Thu, 23 Jan 2025 12:41:02 +0100", "Message-ID": "<20250123114204.79321-13-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-Type": "text/plain; charset=UTF-8", "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": "For the lux algorithm, reference values get calculated based on a tuning\nimage taken at a known lux level. The reference data contains the mean Y\nof the image, lux level, exposure time, gain and aperture. This module\ncalculates these values for insertion into the tuning file.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\n\nChanges in v2:\n- Added this patch\n---\n .../tuning/libtuning/modules/lux/__init__.py | 6 ++\n utils/tuning/libtuning/modules/lux/lux.py | 70 +++++++++++++++++++\n utils/tuning/libtuning/modules/lux/rkisp1.py | 22 ++++++\n 3 files changed, 98 insertions(+)\n create mode 100644 utils/tuning/libtuning/modules/lux/__init__.py\n create mode 100644 utils/tuning/libtuning/modules/lux/lux.py\n create mode 100644 utils/tuning/libtuning/modules/lux/rkisp1.py", "diff": "diff --git a/utils/tuning/libtuning/modules/lux/__init__.py b/utils/tuning/libtuning/modules/lux/__init__.py\nnew file mode 100644\nindex 000000000000..af9d4e08e64f\n--- /dev/null\n+++ b/utils/tuning/libtuning/modules/lux/__init__.py\n@@ -0,0 +1,6 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2025, Ideas on Board\n+\n+from libtuning.modules.lux.lux import Lux\n+from libtuning.modules.lux.rkisp1 import LuxRkISP1\ndiff --git a/utils/tuning/libtuning/modules/lux/lux.py b/utils/tuning/libtuning/modules/lux/lux.py\nnew file mode 100644\nindex 000000000000..5cf7d3baeb5d\n--- /dev/null\n+++ b/utils/tuning/libtuning/modules/lux/lux.py\n@@ -0,0 +1,70 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2019, Raspberry Pi Ltd\n+# Copyright (C) 2025, Ideas on Board\n+#\n+# Base Lux tuning module\n+\n+from ..module import Module\n+\n+import logging\n+import numpy as np\n+\n+logger = logging.getLogger(__name__)\n+\n+\n+class Lux(Module):\n+ type = 'lux'\n+ hr_name = 'LUX (Base)'\n+ out_name = 'GenericLux'\n+\n+ def __init__(self, debug: list):\n+ super().__init__()\n+\n+ self.debug = debug\n+\n+ def calculate_lux_reference_values(self, images):\n+ # The lux calibration is done on a single image. For best effects, the\n+ # image with lux level closest to 1000 is chosen.\n+ imgs = [img for img in images if img.macbeth is not None]\n+ lux_values = [img.lux for img in imgs]\n+ index = lux_values.index(min(lux_values, key=lambda l: abs(1000 - l)))\n+ img = imgs[index]\n+ logger.info(f'Selected image {img.name} for lux calibration')\n+\n+ if img.lux < 50:\n+ logger.warning(f'A Lux level of {img.lux} is very low for proper lux calibration')\n+\n+ ref_y = self.calculate_y(img)\n+ exposure_time = img.exposure\n+ gain = img.againQ8_norm\n+ aperture = 1\n+ logger.info(f'RefY:{ref_y} Exposure time:{exposure_time}µs Gain:{gain} Aperture:{aperture}')\n+ return {'referenceY': ref_y,\n+ 'referenceExposureTime': exposure_time,\n+ 'referenceAnalogueGain': gain,\n+ 'referenceDigitalGain': 1.0,\n+ 'referenceLux': img.lux}\n+\n+ def calculate_y(self, img):\n+ max16Bit = 0xffff\n+ # Average over all grey patches.\n+ ap_r = np.mean(img.patches[0][3::4]) / max16Bit\n+ ap_g = (np.mean(img.patches[1][3::4]) + np.mean(img.patches[2][3::4])) / 2 / max16Bit\n+ ap_b = np.mean(img.patches[3][3::4]) / max16Bit\n+ logger.debug(f'Averaged grey patches: Red: {ap_r}, Green: {ap_g}, Blue: {ap_b}')\n+\n+ # Calculate white balance gains.\n+ gr = ap_g / ap_r\n+ gb = ap_g / ap_b\n+ logger.debug(f'WB gains: Red: {gr} Blue: {gb}')\n+\n+ # Calculate the mean Y value of the whole image\n+ a_r = np.mean(img.channels[0]) * gr\n+ a_g = (np.mean(img.channels[1]) + np.mean(img.channels[2])) / 2\n+ a_b = np.mean(img.channels[3]) * gb\n+ y = 0.299 * a_r + 0.587 * a_g + 0.114 * a_b\n+ y /= max16Bit\n+\n+ return y\n+\ndiff --git a/utils/tuning/libtuning/modules/lux/rkisp1.py b/utils/tuning/libtuning/modules/lux/rkisp1.py\nnew file mode 100644\nindex 000000000000..62d3f94cabd8\n--- /dev/null\n+++ b/utils/tuning/libtuning/modules/lux/rkisp1.py\n@@ -0,0 +1,22 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2024, Ideas on Board\n+#\n+# Lux module for tuning rkisp1\n+\n+from .lux import Lux\n+\n+\n+class LuxRkISP1(Lux):\n+ hr_name = 'Lux (RkISP1)'\n+ out_name = 'Lux'\n+\n+ def __init__(self, **kwargs):\n+ super().__init__(**kwargs)\n+\n+ # We don't need anything from the config file.\n+ def validate_config(self, config: dict) -> bool:\n+ return True\n+\n+ def process(self, config: dict, images: list, outputs: dict) -> dict:\n+ return self.calculate_lux_reference_values(images)\n", "prefixes": [ "v2", "12/17" ] }