[{"id":31612,"web_url":"https://patchwork.libcamera.org/comment/31612/","msgid":"<172837759822.532453.13231961573287540643@ping.linuxembedded.co.uk>","date":"2024-10-08T08:53:18","subject":"Re: [PATCH v3 2/2] ipa: rpi: awb: Add a bias to the AWB search","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck (2024-10-08 09:13:17)\n> In the case of an AWB search failure, the current algorithm logic will\n> return a point on the CT curve closest to where the search finisned.\n> This can be quite undesirable. Instead, add some bias params to the AWB\n> algorithm which will direct the search to a set CT value in the case\n> where statistics become unreliable causing the search to fail.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nAh, I was about to merge the v2, but now I see v3.\n\nv2 passed the CI, so I'll shove this through and merge if nothing else\ncrops up.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/ipa/rpi/controller/rpi/awb.cpp | 23 +++++++++++++++++++++--\n>  src/ipa/rpi/controller/rpi/awb.h   |  4 ++++\n>  2 files changed, 25 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp\n> index 65416d05b28e..9d8e170d1bfe 100644\n> --- a/src/ipa/rpi/controller/rpi/awb.cpp\n> +++ b/src/ipa/rpi/controller/rpi/awb.cpp\n> @@ -170,6 +170,14 @@ int AwbConfig::read(const libcamera::YamlObject &params)\n>         whitepointB = params[\"whitepoint_b\"].get<double>(0.0);\n>         if (bayes == false)\n>                 sensitivityR = sensitivityB = 1.0; /* nor do sensitivities make any sense */\n> +       /*\n> +        * The biasProportion parameter adds a small proportion of the counted\n> +        * pixles to a region biased to the biasCT colour temperature.\n> +        *\n> +        * A typical value for biasProportion would be between 0.05 to 0.1.\n> +        */\n> +       biasProportion = params[\"bias_proportion\"].get<double>(0.0);\n> +       biasCT = params[\"bias_ct\"].get<double>(kDefaultCT);\n>         return 0;\n>  }\n>  \n> @@ -410,7 +418,8 @@ void Awb::asyncFunc()\n>  \n>  static void generateStats(std::vector<Awb::RGB> &zones,\n>                           StatisticsPtr &stats, double minPixels,\n> -                         double minG, Metadata &globalMetadata)\n> +                         double minG, Metadata &globalMetadata,\n> +                         double biasProportion, double biasCtR, double biasCtB)\n>  {\n>         std::scoped_lock<RPiController::Metadata> l(globalMetadata);\n>  \n> @@ -423,6 +432,14 @@ static void generateStats(std::vector<Awb::RGB> &zones,\n>                                 continue;\n>                         zone.R = region.val.rSum / region.counted;\n>                         zone.B = region.val.bSum / region.counted;\n> +                       /*\n> +                        * Add some bias samples to allow the search to tend to a\n> +                        * bias CT in failure cases.\n> +                        */\n> +                       const unsigned int proportion = biasProportion * region.counted;\n> +                       zone.R += proportion * biasCtR;\n> +                       zone.B += proportion * biasCtB;\n> +                       zone.G += proportion * 1.0;\n>                         /* Factor in the ALSC applied colour shading correction if required. */\n>                         const AlscStatus *alscStatus = globalMetadata.getLocked<AlscStatus>(\"alsc.status\");\n>                         if (stats->colourStatsPos == Statistics::ColourStatsPos::PreLsc && alscStatus) {\n> @@ -443,7 +460,9 @@ void Awb::prepareStats()\n>          * any LSC compensation.  We also ignore config_.fast in this version.\n>          */\n>         generateStats(zones_, statistics_, config_.minPixels,\n> -                     config_.minG, getGlobalMetadata());\n> +                     config_.minG, getGlobalMetadata(),\n> +                     config_.biasProportion, config_.ctR.eval(config_.biasCT),\n> +                     config_.ctB.eval(config_.biasCT));\n>         /*\n>          * apply sensitivities, so values appear to come from our \"canonical\"\n>          * sensor.\n> diff --git a/src/ipa/rpi/controller/rpi/awb.h b/src/ipa/rpi/controller/rpi/awb.h\n> index ab30f4fa51c1..5d628b47c8a6 100644\n> --- a/src/ipa/rpi/controller/rpi/awb.h\n> +++ b/src/ipa/rpi/controller/rpi/awb.h\n> @@ -87,6 +87,10 @@ struct AwbConfig {\n>         double whitepointR;\n>         double whitepointB;\n>         bool bayes; /* use Bayesian algorithm */\n> +       /* proportion of counted samples to add for the search bias */\n> +       double biasProportion;\n> +       /* CT target for the search bias */\n> +       double biasCT;\n>  };\n>  \n>  class Awb : public AwbAlgorithm\n> -- \n> 2.34.1\n>","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 E4CC6BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  8 Oct 2024 08:53:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AE13A6353A;\n\tTue,  8 Oct 2024 10:53:22 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 407F362C8E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Oct 2024 10:53:21 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B8E133D6;\n\tTue,  8 Oct 2024 10:51:44 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ZkdVVQ1Z\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1728377504;\n\tbh=0qAKDz/SBQtzHXwVQmAz0UuUepRKfV9c1lQKqqXLg8c=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=ZkdVVQ1ZRimvgnnqBa43MtBo/E2LRwqLBjzjEP4AOcgs9+Hw4k1nQIvl/jCsqvdCX\n\tg/vOayJKXQY0g0eMPZv6VorZf7keHCoGD52ADDtXcET6oK9LdXzF1fhtYdaLQg/gm6\n\tSmbbrFZT7o3KQhPKFThJy26kRDnK+389XplnSAEU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20241008081317.24602-2-naush@raspberrypi.com>","References":"<20241008081317.24602-1-naush@raspberrypi.com>\n\t<20241008081317.24602-2-naush@raspberrypi.com>","Subject":"Re: [PATCH v3 2/2] ipa: rpi: awb: Add a bias to the AWB search","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Naushir Patuck <naush@raspberrypi.com>,\n\tDavid Plowman <david.plowman@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 08 Oct 2024 09:53:18 +0100","Message-ID":"<172837759822.532453.13231961573287540643@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}},{"id":31622,"web_url":"https://patchwork.libcamera.org/comment/31622/","msgid":"<20241008143210.GB16232@pendragon.ideasonboard.com>","date":"2024-10-08T14:32:10","subject":"Re: [PATCH v3 2/2] ipa: rpi: awb: Add a bias to the AWB search","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Tue, Oct 08, 2024 at 09:13:17AM +0100, Naushir Patuck wrote:\n> In the case of an AWB search failure, the current algorithm logic will\n> return a point on the CT curve closest to where the search finisned.\n> This can be quite undesirable. Instead, add some bias params to the AWB\n> algorithm which will direct the search to a set CT value in the case\n> where statistics become unreliable causing the search to fail.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>\n> ---\n>  src/ipa/rpi/controller/rpi/awb.cpp | 23 +++++++++++++++++++++--\n>  src/ipa/rpi/controller/rpi/awb.h   |  4 ++++\n>  2 files changed, 25 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp\n> index 65416d05b28e..9d8e170d1bfe 100644\n> --- a/src/ipa/rpi/controller/rpi/awb.cpp\n> +++ b/src/ipa/rpi/controller/rpi/awb.cpp\n> @@ -170,6 +170,14 @@ int AwbConfig::read(const libcamera::YamlObject &params)\n>  \twhitepointB = params[\"whitepoint_b\"].get<double>(0.0);\n>  \tif (bayes == false)\n>  \t\tsensitivityR = sensitivityB = 1.0; /* nor do sensitivities make any sense */\n> +\t/*\n> +\t * The biasProportion parameter adds a small proportion of the counted\n> +\t * pixles to a region biased to the biasCT colour temperature.\n\ns/pixles/pixels/\n\n> +\t *\n> +\t * A typical value for biasProportion would be between 0.05 to 0.1.\n> +\t */\n> +\tbiasProportion = params[\"bias_proportion\"].get<double>(0.0);\n> +\tbiasCT = params[\"bias_ct\"].get<double>(kDefaultCT);\n>  \treturn 0;\n>  }\n>  \n> @@ -410,7 +418,8 @@ void Awb::asyncFunc()\n>  \n>  static void generateStats(std::vector<Awb::RGB> &zones,\n>  \t\t\t  StatisticsPtr &stats, double minPixels,\n> -\t\t\t  double minG, Metadata &globalMetadata)\n> +\t\t\t  double minG, Metadata &globalMetadata,\n> +\t\t\t  double biasProportion, double biasCtR, double biasCtB)\n>  {\n>  \tstd::scoped_lock<RPiController::Metadata> l(globalMetadata);\n>  \n> @@ -423,6 +432,14 @@ static void generateStats(std::vector<Awb::RGB> &zones,\n>  \t\t\t\tcontinue;\n>  \t\t\tzone.R = region.val.rSum / region.counted;\n>  \t\t\tzone.B = region.val.bSum / region.counted;\n> +\t\t\t/*\n> +\t\t\t * Add some bias samples to allow the search to tend to a\n> +\t\t\t * bias CT in failure cases.\n> +\t\t\t */\n> +\t\t\tconst unsigned int proportion = biasProportion * region.counted;\n> +\t\t\tzone.R += proportion * biasCtR;\n> +\t\t\tzone.B += proportion * biasCtB;\n> +\t\t\tzone.G += proportion * 1.0;\n>  \t\t\t/* Factor in the ALSC applied colour shading correction if required. */\n>  \t\t\tconst AlscStatus *alscStatus = globalMetadata.getLocked<AlscStatus>(\"alsc.status\");\n>  \t\t\tif (stats->colourStatsPos == Statistics::ColourStatsPos::PreLsc && alscStatus) {\n> @@ -443,7 +460,9 @@ void Awb::prepareStats()\n>  \t * any LSC compensation.  We also ignore config_.fast in this version.\n>  \t */\n>  \tgenerateStats(zones_, statistics_, config_.minPixels,\n> -\t\t      config_.minG, getGlobalMetadata());\n> +\t\t      config_.minG, getGlobalMetadata(),\n> +\t\t      config_.biasProportion, config_.ctR.eval(config_.biasCT),\n> +\t\t      config_.ctB.eval(config_.biasCT));\n>  \t/*\n>  \t * apply sensitivities, so values appear to come from our \"canonical\"\n>  \t * sensor.\n> diff --git a/src/ipa/rpi/controller/rpi/awb.h b/src/ipa/rpi/controller/rpi/awb.h\n> index ab30f4fa51c1..5d628b47c8a6 100644\n> --- a/src/ipa/rpi/controller/rpi/awb.h\n> +++ b/src/ipa/rpi/controller/rpi/awb.h\n> @@ -87,6 +87,10 @@ struct AwbConfig {\n>  \tdouble whitepointR;\n>  \tdouble whitepointB;\n>  \tbool bayes; /* use Bayesian algorithm */\n> +\t/* proportion of counted samples to add for the search bias */\n> +\tdouble biasProportion;\n> +\t/* CT target for the search bias */\n> +\tdouble biasCT;\n>  };\n>  \n>  class Awb : public AwbAlgorithm","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 B4497BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  8 Oct 2024 14:32:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BBA53618CB;\n\tTue,  8 Oct 2024 16:32:17 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A8F43618C9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Oct 2024 16:32:15 +0200 (CEST)","from pendragon.ideasonboard.com (unknown [132.205.230.3])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BD3FCA47;\n\tTue,  8 Oct 2024 16:30:38 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"AFtTMIMH\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1728397839;\n\tbh=gglX7w7AbZGBIOOhNVKi2ikFoEftuMFq4FEhniqvzW8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=AFtTMIMHPS9LJxR24j9xs7KZQwX/ErTotCUklw+mesHf0M7ajASb2bnCL5/Ot4IAT\n\tLGi6QOQBJ7pM/eF3bX35eJ3a+JZGMf8NIwELCdj/UlJPsd834xTlu6zeMkWEVYZqcD\n\tVmOyc2sZJYjCxLVAv6hhvXm/4FC/7RXfQ97tmKLk=","Date":"Tue, 8 Oct 2024 17:32:10 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tDavid Plowman <david.plowman@raspberrypi.com>","Subject":"Re: [PATCH v3 2/2] ipa: rpi: awb: Add a bias to the AWB search","Message-ID":"<20241008143210.GB16232@pendragon.ideasonboard.com>","References":"<20241008081317.24602-1-naush@raspberrypi.com>\n\t<20241008081317.24602-2-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20241008081317.24602-2-naush@raspberrypi.com>","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>"}}]