{"id":17773,"url":"https://patchwork.libcamera.org/api/patches/17773/?format=json","web_url":"https://patchwork.libcamera.org/patch/17773/","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-3-paul.elder@ideasonboard.com>","date":"2022-11-10T17:31:44","name":"[libcamera-devel,v3,02/12] utils: tuning: libtuning: Implement math helpers","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"8b19e0e7b9d5a67c91bbf11aa6c08221f3daad22","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/17773/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/17773/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17773/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 D921FBD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Nov 2022 17:32:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3074A63086;\n\tThu, 10 Nov 2022 18:32:21 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3C66463075\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Nov 2022 18:32:20 +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 C792B32A;\n\tThu, 10 Nov 2022 18:32:18 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1668101541;\n\tbh=cDeERBi0lVPKemJBXXs6ncnPI/AH+uP5QuGku0ZDk+c=;\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=0wjm8iBYVvoBgedZVi0YtjGRnm4VSNotkV3/QryqOexMm/uqVWHV3SpKKfN0V6+du\n\tPOz2V8M5gbugLyf+mlSG2FWHXrtvFW7dfzjLGJq4Wmth8/ogGG5bqCS3ADPDvURT/X\n\tXMnxwFfwY1naqZJX2i3F/7zVAn5At/pBLxQnDdaF8nqcwJk3G1HFrFZQTQgqGA2IeP\n\t+VGrWhoNAs+uVME0VMdfmjMidFz5d9undLBlAnDcUDrw77VqLni/CSQXU9cNGu9LxX\n\tmqPDx0o02DuQkGQP68ky5/1c24RqL/vC5in0VJpnSCU9V77f1tzYPGuKa1gD3NGMib\n\tbmWETIcDBIoHQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1668101540;\n\tbh=cDeERBi0lVPKemJBXXs6ncnPI/AH+uP5QuGku0ZDk+c=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=FuPrsHOFGL3Svq6f5VWflILEIjmbbWdEMROtYdIuCRIWlmftC0Ja43d+rIkAjRwc9\n\tWXaMj8Ou4q/a5+YoIdTVIF1VGLUVlXBgscWW4tO5RrDxC25cs0NRmeSsAStQdOBDNJ\n\tp+JooCiDdQ1ZLXAfnOqi8axErEZvqnAEgt3JfkTk="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"FuPrsHOF\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 11 Nov 2022 02:31:44 +0900","Message-Id":"<20221110173154.488445-3-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 02/12] utils: tuning: libtuning:\n\tImplement math helpers","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":"Implement math helpers for libtuning. This includes:\n- Average, a wrapper class for numpy averaging functions\n- Gradient, a class that represents gradients, for distributing and\n  mapping\n- Smoothing, a wrapper class for cv2 smoothing functions\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nChanges in v3:\n- Newly split from the first patch \"utils: tuning: libtuning: Implement\n  the core of libtuning\"\n  - See changelog from that patch\n---\n utils/tuning/libtuning/average.py   | 21 ++++++++\n utils/tuning/libtuning/gradient.py  | 75 +++++++++++++++++++++++++++++\n utils/tuning/libtuning/smoothing.py | 24 +++++++++\n 3 files changed, 120 insertions(+)\n create mode 100644 utils/tuning/libtuning/average.py\n create mode 100644 utils/tuning/libtuning/gradient.py\n create mode 100644 utils/tuning/libtuning/smoothing.py","diff":"diff --git a/utils/tuning/libtuning/average.py b/utils/tuning/libtuning/average.py\nnew file mode 100644\nindex 00000000..e28770d7\n--- /dev/null\n+++ b/utils/tuning/libtuning/average.py\n@@ -0,0 +1,21 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>\n+#\n+# average.py - Wrapper for numpy averaging functions to enable duck-typing\n+\n+import numpy as np\n+\n+\n+# @brief Wrapper for np averaging functions so that they can be duck-typed\n+class Average(object):\n+    def __init__(self):\n+        pass\n+\n+    def average(self, np_array):\n+        raise NotImplementedError\n+\n+\n+class Mean(Average):\n+    def average(self, np_array):\n+        return np.mean(np_array)\ndiff --git a/utils/tuning/libtuning/gradient.py b/utils/tuning/libtuning/gradient.py\nnew file mode 100644\nindex 00000000..64a96369\n--- /dev/null\n+++ b/utils/tuning/libtuning/gradient.py\n@@ -0,0 +1,75 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>\n+#\n+# gradient.py - Gradients that can be used to distribute or map numbers\n+\n+import libtuning as lt\n+\n+import math\n+from numbers import Number\n+\n+\n+# @brief Gradient for how to allocate pixels to sectors\n+# @description There are no parameters for the gradients as the domain is the\n+#              number of pixels and the range is the number of sectors, and\n+#              there is only one curve that has a startpoint and endpoint at\n+#              (0, 0) and at (#pixels, #sectors). The exception is for curves\n+#              that *do* have multiple solutions for only two points, such as\n+#              gaussian, and curves of higher polynomial orders if we had them.\n+#\n+# \\todo There will probably be a helper in the Gradient class, as I have a\n+# feeling that all the other curves (besides Linear and Gaussian) can be\n+# implemented in the same way.\n+class Gradient(object):\n+    def __init__(self):\n+        pass\n+\n+    # @brief Distribute pixels into sectors (only in one dimension)\n+    # @param domain Number of pixels\n+    # @param sectors Number of sectors\n+    # @return A list of number of pixels in each sector\n+    def distribute(self, domain: list, sectors: list, ) -> list:\n+        raise NotImplementedError\n+\n+    # @brief Map a number on a curve\n+    # @param domain Domain of the curve\n+    # @param rang Range of the curve\n+    # @param x Input on the domain of the curve\n+    # @return y from the range of the curve\n+    def map(self, domain: tuple, rang: tuple, x: Number) -> Number:\n+        raise NotImplementedError\n+\n+\n+class Linear(Gradient):\n+    # @param remainder Mode of handling remainder\n+    def __init__(self, remainder: lt.Remainder = lt.Remainder.Float):\n+        self.remainder = remainder\n+\n+    def distribute(self, domain: list, sectors: list) -> list:\n+        size = domain / sectors\n+        rem = domain % sectors\n+\n+        if rem == 0:\n+            return [int(size)] * sectors\n+\n+        size = math.ceil(size)\n+        rem = domain % size\n+        output_sectors = [int(size)] * (sectors - 1)\n+\n+        if self.remainder == lt.Remainder.Float:\n+            size = domain / sectors\n+            output_sectors = [size] * sectors\n+        elif self.remainder == lt.Remainder.DistributeFront:\n+            output_sectors.append(int(rem))\n+        elif self.remainder == lt.Remainder.DistributeBack:\n+            output_sectors.insert(0, int(rem))\n+        else:\n+            raise ValueError\n+\n+        return output_sectors\n+\n+    def map(self, domain: tuple, rang: tuple, x: Number) -> Number:\n+        m = (rang[1] - rang[0]) / (domain[1] - domain[0])\n+        b = rang[0] - m * domain[0]\n+        return m * x + b\ndiff --git a/utils/tuning/libtuning/smoothing.py b/utils/tuning/libtuning/smoothing.py\nnew file mode 100644\nindex 00000000..b8a5a242\n--- /dev/null\n+++ b/utils/tuning/libtuning/smoothing.py\n@@ -0,0 +1,24 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>\n+#\n+# smoothing.py - Wrapper for cv2 smoothing functions to enable duck-typing\n+\n+import cv2\n+\n+\n+# @brief Wrapper for cv2 smoothing functions so that they can be duck-typed\n+class Smoothing(object):\n+    def __init__(self):\n+        pass\n+\n+    def smoothing(self, src):\n+        raise NotImplementedError\n+\n+\n+class MedianBlur(Smoothing):\n+    def __init__(self, ksize):\n+        self.ksize = ksize\n+\n+    def smoothing(self, src):\n+        return cv2.medianBlur(src.astype('float32'), self.ksize).astype('float64')\n","prefixes":["libcamera-devel","v3","02/12"]}