{"id":17775,"url":"https://patchwork.libcamera.org/api/patches/17775/?format=json","web_url":"https://patchwork.libcamera.org/patch/17775/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20221110173154.488445-5-paul.elder@ideasonboard.com>","date":"2022-11-10T17:31:46","name":"[libcamera-devel,v3,04/12] utils: libtuning: modules: Add base LSC module","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"04dac79219f4ef1ffc79a7611540e511662ce0cd","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17775/mbox/","series":[{"id":3603,"url":"https://patchwork.libcamera.org/api/series/3603/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3603","date":"2022-11-10T17:31:42","name":"utils: tuning: Add a new tuning infrastructure","version":3,"mbox":"https://patchwork.libcamera.org/series/3603/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17775/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17775/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 4EF33BD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Nov 2022 17:32:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 12A5C63092;\n\tThu, 10 Nov 2022 18:32:25 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3F58D63085\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Nov 2022 18:32:24 +0100 (CET)","from pyrite.tail37cf.ts.net (h175-177-042-159.catv02.itscom.jp\n\t[175.177.42.159])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7B5884D4;\n\tThu, 10 Nov 2022 18:32:22 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1668101545;\n\tbh=3cdWwHM8Ia0AWP/tCkVhKltnyHW7TVzU9UusVKHhod0=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=IWGbo4PI90/VUmAD/tWqPs8u9PkJGWG3lBbsLOaplqfU1Rr0jPFXugHmds1dgvw33\n\tr4gk+CVJsMKy7FTj3Jl0BOAZcpT+8OT8yOT/E5ZxY+XKvHvgTpvC6Y7+8pbXN0FwgV\n\tt9MXhXbJXhn6hslxbZJCu8GqAlieuaf9qZpwy8E3Sw7kKf9WRB0SCrjcdqMXqBxWJK\n\tVjz5oPc5xkJZdnLNfjHKWNKNj07iyVMnk3h3t4GJej/knnx5X5N7CdXmmOLpP+j2iQ\n\tn3ZrSuCJBXXOGhILYBA2VAZPCTwjDLPBon0locAmy5gPaQw8fat8+/KsoLq8Nn5jzq\n\tkrZYxZFsoq/EQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1668101544;\n\tbh=3cdWwHM8Ia0AWP/tCkVhKltnyHW7TVzU9UusVKHhod0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=oMEhoPibxoYOx/Yk2gA1MXqBoWneDxg/ioWHg9aRtvnzYwbufElg/2Yn8H9MDVsIf\n\t9iv6HZQYM4+LuPGUXZlThX+4qrrmeTJn6fDrzh5NopSncisAGNyYcLiX+CgpYh2OId\n\tDH+OBgOFVzXsKy2UhIocrTx0iIXRP1s0K1V+B0Vo="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"oMEhoPib\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 11 Nov 2022 02:31:46 +0900","Message-Id":"<20221110173154.488445-5-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.35.1","In-Reply-To":"<20221110173154.488445-1-paul.elder@ideasonboard.com>","References":"<20221110173154.488445-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 04/12] utils: libtuning: modules: Add\n\tbase LSC module","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>","From":"Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Paul Elder <paul.elder@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add a base LSC module to libtuning's collection of modules. It is based\non raspberrypi's ctt's ALSC, but customizable for different lens shading\ntable sizes, among other things. It alone is insufficient as a module,\nbut it provides utilities that are useful for and which will simplify\nimplementing LSC modules.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v3:\n- rename ALSC to LSC\n- update changelog to more accurately reflect the redesign (splitting\n  core LSC from Raspberry Pi ALSC and rkisp1 LSC)\n\nChanges in v2:\n- fix python errors\n- fix style\n- add SPDX and copyright\n- don't call super().validateConfig()\n- fix sector splitting\n  - i forgot that we have to half the image size for each color channel\n- make the base ALSC module into an abstract module, which can be easily\n  used by other platforms to derive their own ALSC modules (see rkisp1's\n  module later in this series; i think it's quite nice)\n---\n .../tuning/libtuning/modules/lsc/__init__.py  |  5 ++\n utils/tuning/libtuning/modules/lsc/lsc.py     | 72 +++++++++++++++++++\n 2 files changed, 77 insertions(+)\n create mode 100644 utils/tuning/libtuning/modules/lsc/__init__.py\n create mode 100644 utils/tuning/libtuning/modules/lsc/lsc.py","diff":"diff --git a/utils/tuning/libtuning/modules/lsc/__init__.py b/utils/tuning/libtuning/modules/lsc/__init__.py\nnew file mode 100644\nindex 00000000..47d9b846\n--- /dev/null\n+++ b/utils/tuning/libtuning/modules/lsc/__init__.py\n@@ -0,0 +1,5 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>\n+\n+from libtuning.modules.lsc.lsc import LSC\ndiff --git a/utils/tuning/libtuning/modules/lsc/lsc.py b/utils/tuning/libtuning/modules/lsc/lsc.py\nnew file mode 100644\nindex 00000000..344a07a3\n--- /dev/null\n+++ b/utils/tuning/libtuning/modules/lsc/lsc.py\n@@ -0,0 +1,72 @@\n+# SPDX-License-Identifier: BSD-2-Clause\n+#\n+# Copyright (C) 2019, Raspberry Pi Ltd\n+# Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>\n+\n+from ..module import Module\n+\n+import libtuning as lt\n+import libtuning.utils as utils\n+\n+import numpy as np\n+\n+\n+class LSC(Module):\n+    type = 'lsc'\n+    hr_name = 'LSC (Base)'\n+    out_name = 'GenericLSC'\n+\n+    def __init__(self, *,\n+                 debug: list,\n+                 sector_shape: tuple,\n+                 sector_x_gradient: lt.Gradient,\n+                 sector_y_gradient: lt.Gradient,\n+                 sector_average_function: lt.Average,\n+                 smoothing_function: lt.Smoothing):\n+        super().__init__()\n+\n+        self.debug = debug\n+\n+        self.sector_shape = sector_shape\n+        self.sector_x_gradient = sector_x_gradient\n+        self.sector_y_gradient = sector_y_gradient\n+        self.sector_average_function = sector_average_function\n+\n+        self.smoothing_function = smoothing_function\n+\n+    def _enumerate_lsc_images(self, images):\n+        for image in images:\n+            if image.lsc_only:\n+                yield image\n+\n+    def _get_grid(self, channel, img_w, img_h):\n+        # List of number of pixels in each sector\n+        sectors_x = self.sector_x_gradient.distribute(img_w / 2, self.sector_shape[0])\n+        sectors_y = self.sector_y_gradient.distribute(img_h / 2, self.sector_shape[1])\n+\n+        grid = []\n+\n+        r = 0\n+        for y in sectors_y:\n+            c = 0\n+            for x in sectors_x:\n+                grid.append(self.sector_average_function.average(channel[r:r + y, c:c + x]))\n+                c += x\n+            r += y\n+\n+        return np.array(grid)\n+\n+    def _lsc_single_channel(self, channel: np.array,\n+                            image: lt.Image, green_grid: np.array = None):\n+        grid = self._get_grid(channel, image.w, image.h)\n+        grid -= image.blacklevel_16\n+        if green_grid is None:\n+            table = np.reshape(1 / grid, self.sector_shape[::-1])\n+        else:\n+            table = np.reshape(green_grid / grid, self.sector_shape[::-1])\n+        table = self.smoothing_function.smoothing(table)\n+\n+        if green_grid is None:\n+            table = table / np.min(table)\n+\n+        return table, grid\n","prefixes":["libcamera-devel","v3","04/12"]}