{"id":13899,"url":"https://patchwork.libcamera.org/api/1.1/patches/13899/?format=json","web_url":"https://patchwork.libcamera.org/patch/13899/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20210923081625.60276-8-jeanmichel.hautbois@ideasonboard.com>","date":"2021-09-23T08:16:20","name":"[libcamera-devel,07/12] ipa: ipu3: awb: Correct the relevant zones proportion","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"af8149aefc3e19f8ecbcafdf231b6d1d4903d097","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/1.1/people/75/?format=json","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13899/mbox/","series":[{"id":2548,"url":"https://patchwork.libcamera.org/api/1.1/series/2548/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2548","date":"2021-09-23T08:16:13","name":"Improve ImgU statistics usage","version":1,"mbox":"https://patchwork.libcamera.org/series/2548/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13899/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13899/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 A016FBF01C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Sep 2021 08:16:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4245069197;\n\tThu, 23 Sep 2021 10:16:43 +0200 (CEST)","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 ACCF869194\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Sep 2021 10:16:31 +0200 (CEST)","from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:392e:dcd2:2bf6:d61c])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5DE4458B;\n\tThu, 23 Sep 2021 10:16:31 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"AYYFETjI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1632384991;\n\tbh=W76hqxG6KF4FWSImWFPug7algIpCbhYfzpChqHonqYw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=AYYFETjIPh1IDVjOS6CcAecklmqWn14zTFHAJRoaMNxqssafJf2WT86B4XbNLIvXh\n\t0ROaATecutEqS/DQelzNpx/BJR9vCm3l5aVhktMnN6IVKqALO4D1++wzhX9BjpFVKV\n\t5nqKGlZC098t0f3ssS0zX+UHsGPHvJU/FRmjHBLw=","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 23 Sep 2021 10:16:20 +0200","Message-Id":"<20210923081625.60276-8-jeanmichel.hautbois@ideasonboard.com>","X-Mailer":"git-send-email 2.30.2","In-Reply-To":"<20210923081625.60276-1-jeanmichel.hautbois@ideasonboard.com>","References":"<20210923081625.60276-1-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 07/12] ipa: ipu3: awb: Correct the\n\trelevant zones proportion","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 algorithm uses the statistics of a cell only if there is not too\nmuch saturated pixels in it. The grey world algorithm works fine when\nthere are a limited number of outliers.\nConsider a valid zone to be at least 80% of unsaturated cells in it.\nThis value could very well be configurable, and make the algorithm more\nor less tolerant.\n\nWhile at it, implement it in a configure() call as it will not change\nduring execution, and cache the cellsPerZone values.\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/awb.cpp | 32 +++++++++++++++++++++++---------\n src/ipa/ipu3/algorithms/awb.h   |  5 +++++\n 2 files changed, 28 insertions(+), 9 deletions(-)","diff":"diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp\nindex 51a38d05..800d023c 100644\n--- a/src/ipa/ipu3/algorithms/awb.cpp\n+++ b/src/ipa/ipu3/algorithms/awb.cpp\n@@ -17,7 +17,6 @@ namespace ipa::ipu3::algorithms {\n \n LOG_DEFINE_CATEGORY(IPU3Awb)\n \n-static constexpr uint32_t kMinZonesCounted = 16;\n static constexpr uint32_t kMinGreenLevelInZone = 32;\n \n /**\n@@ -169,6 +168,24 @@ Awb::Awb()\n \n Awb::~Awb() = default;\n \n+int Awb::configure(IPAContext &context,\n+\t\t   [[maybe_unused]] const IPAConfigInfo &configInfo)\n+{\n+\tconst ipu3_uapi_grid_config &grid = context.configuration.grid.bdsGrid;\n+\n+\tcellsPerZoneX_ = round(grid.width / static_cast<double>(kAwbStatsSizeX));\n+\tcellsPerZoneY_ = round(grid.height / static_cast<double>(kAwbStatsSizeY));\n+\n+\t/*\n+\t * Configure the minimum proportion of cells counted within a zone\n+\t * for it to be relevant for the grey world algorithm.\n+\t * \\todo This proportion could be configured.\n+\t */\n+\tcellsPerZoneThreshold_ = (cellsPerZoneX_ * cellsPerZoneY_) * 80 / 100;\n+\n+\treturn 0;\n+}\n+\n /**\n  * The function estimates the correlated color temperature using\n  * from RGB color space input.\n@@ -205,7 +222,7 @@ void Awb::generateZones(std::vector<RGB> &zones)\n \tfor (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {\n \t\tRGB zone;\n \t\tdouble counted = awbStats_[i].counted;\n-\t\tif (counted >= kMinZonesCounted) {\n+\t\tif (counted >= cellsPerZoneThreshold_) {\n \t\t\tzone.G = awbStats_[i].sum.green / counted;\n \t\t\tif (zone.G >= kMinGreenLevelInZone) {\n \t\t\t\tzone.R = awbStats_[i].sum.red / counted;\n@@ -220,19 +237,16 @@ void Awb::generateZones(std::vector<RGB> &zones)\n void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats,\n \t\t\t   const ipu3_uapi_grid_config &grid)\n {\n-\tuint32_t cellsPerZoneX = round(grid.width / static_cast<double>(kAwbStatsSizeX));\n-\tuint32_t cellsPerZoneY = round(grid.height / static_cast<double>(kAwbStatsSizeY));\n-\n \t/*\n \t * Generate a (kAwbStatsSizeX x kAwbStatsSizeY) array from the IPU3 grid which is\n \t * (grid.width x grid.height).\n \t */\n-\tfor (unsigned int cellY = 0; cellY < kAwbStatsSizeY * cellsPerZoneY; cellY++) {\n-\t\tfor (unsigned int cellX = 0; cellX < kAwbStatsSizeX * cellsPerZoneX; cellX++) {\n+\tfor (unsigned int cellY = 0; cellY < kAwbStatsSizeY * cellsPerZoneY_; cellY++) {\n+\t\tfor (unsigned int cellX = 0; cellX < kAwbStatsSizeX * cellsPerZoneX_; cellX++) {\n \t\t\tuint32_t cellPosition = (cellY * grid.width + cellX)\n \t\t\t\t\t      * sizeof(Ipu3AwbCell);\n-\t\t\tuint32_t zoneX = cellX / cellsPerZoneX;\n-\t\t\tuint32_t zoneY = cellY / cellsPerZoneY;\n+\t\t\tuint32_t zoneX = cellX / cellsPerZoneX_;\n+\t\t\tuint32_t zoneY = cellY / cellsPerZoneY_;\n \n \t\t\tuint32_t awbZonePosition = zoneY * kAwbStatsSizeX + zoneX;\n \ndiff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h\nindex 3385ebe7..681d8c2b 100644\n--- a/src/ipa/ipu3/algorithms/awb.h\n+++ b/src/ipa/ipu3/algorithms/awb.h\n@@ -48,6 +48,7 @@ public:\n \tAwb();\n \t~Awb();\n \n+\tint configure(IPAContext &context, const IPAConfigInfo &configInfo) override;\n \tvoid prepare(IPAContext &context, ipu3_uapi_params *params) override;\n \tvoid process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;\n \n@@ -85,6 +86,10 @@ private:\n \tstd::vector<RGB> zones_;\n \tAccumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];\n \tAwbStatus asyncResults_;\n+\n+\tuint32_t cellsPerZoneX_;\n+\tuint32_t cellsPerZoneY_;\n+\tuint32_t cellsPerZoneThreshold_;\n };\n \n } /* namespace ipa::ipu3::algorithms */\n","prefixes":["libcamera-devel","07/12"]}