[{"id":20342,"web_url":"https://patchwork.libcamera.org/comment/20342/","msgid":"<YXDMKn1LKCKYgfs9@pendragon.ideasonboard.com>","date":"2021-10-21T02:10:50","subject":"Re: [libcamera-devel] [PATCH v2 03/13] ipa: ipu3: awb: Use\n\tsaturation under 90%","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jean-Michel,\n\nThank you for the patch.\n\nOn Wed, Oct 20, 2021 at 05:45:57PM +0200, Jean-Michel Hautbois wrote:\n> The AWB grey world algorithm tries to find a grey value and it can't do\n> it on over-exposed images. To exclude those, the saturation ratio is\n> used for each cell, and the cell is included only if this ratio is 0.\n> \n> Now that we have changed the threshold, more cells may be considered as\n> partially saturated and excluded, preventing the algorithm from running\n> efficiently.\n> \n> Change that behaviour, and consider 90% as a good enough ratio.\n> \n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n>  src/ipa/ipu3/algorithms/awb.cpp | 22 ++++++++++++++++++++--\n>  1 file changed, 20 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp\n> index e44bbd6c..62c72cce 100644\n> --- a/src/ipa/ipu3/algorithms/awb.cpp\n> +++ b/src/ipa/ipu3/algorithms/awb.cpp\n> @@ -19,6 +19,12 @@ LOG_DEFINE_CATEGORY(IPU3Awb)\n>  \n>  static constexpr uint32_t kMinGreenLevelInZone = 32;\n>  \n> +/* Minimum proportion of cells counted within a zone for it to be relevant */\n> +static constexpr double kMinRelevantCellsRatio = 0.8;\n> +\n> +/* Number of cells below the saturation ratio */\n> +static constexpr uint32_t kSaturationThreshold = 255 * 90 / 100;\n\nIsn't this the ratio of saturated pixels in the cell, not the number of\ncells ?\n\n/*\n * Maximum ratio of saturated pixels in a cell for the cell to be considered\n * non-saturated and counted by the AWB algorithm.\n */\nstatic constexpr uint32_t kMaxCellSaturationRatio = 255 * 90 / 100;\n\nMaybe the first constant could then become\n\n/*\n * Minimum proportion of non-saturated cells in a zone for the zone to be used\n * by the AWB algorithm.\n */\nstatic constexpr double kMinCellsPerZoneRatio = 0.8;\n\n(this matches the \"cells per zone\" from the cellsPerZoneThreshold_\nvariable below)\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\n>  /**\n>   * \\struct Accumulator\n>   * \\brief RGB statistics for a given zone\n> @@ -160,7 +166,8 @@ int Awb::configure(IPAContext &context,\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> +\tcellsPerZoneThreshold_ = cellsPerZoneX_ * cellsPerZoneY_ * kMinRelevantCellsRatio;\n> +\tLOG(IPU3Awb, Debug) << \"Threshold for AWB is set to \" << cellsPerZoneThreshold_;\n>  \n>  \treturn 0;\n>  }\n> @@ -234,7 +241,18 @@ void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)\n>  \t\t\t\treinterpret_cast<const ipu3_uapi_awb_set_item *>(\n>  \t\t\t\t\t&stats->awb_raw_buffer.meta_data[cellPosition]\n>  \t\t\t\t);\n> -\t\t\tif (currentCell->sat_ratio == 0) {\n> +\n> +\t\t\t/*\n> +\t\t\t * Use cells which have less than 90%\n> +\t\t\t * saturation as an initial means to include\n> +\t\t\t * otherwise bright cells which are not fully\n> +\t\t\t * saturated.\n> +\t\t\t *\n> +\t\t\t * \\todo The 90% saturation rate may require\n> +\t\t\t * further empirical measurements and\n> +\t\t\t * optimisation during camera tuning phases.\n> +\t\t\t */\n> +\t\t\tif (currentCell->sat_ratio <= kSaturationThreshold) {\n>  \t\t\t\t/* The cell is not saturated, use the current cell */\n>  \t\t\t\tawbStats_[awbZonePosition].counted++;\n>  \t\t\t\tuint32_t greenValue = currentCell->Gr_avg + currentCell->Gb_avg;","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 ECA5BBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 21 Oct 2021 02:11:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4901368F61;\n\tThu, 21 Oct 2021 04:11:12 +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 6AEB268F5B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 Oct 2021 04:11:10 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CAAB893;\n\tThu, 21 Oct 2021 04:11:09 +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=\"OcAiGlBw\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1634782270;\n\tbh=+YIku7U8maP9c3vQpPub3JhoBn3/WIS0bACtAaRgJO4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=OcAiGlBw7QE0r1KvJvWJXmft718yxhNA7WpHHB1VgnWvtBXxgaTd5RJJ0ayoUgb2w\n\tZzMHMCSQJx+5ShUGe6GFuRakfA8uv/UyA/Zo3HylNALwBNXFNOkajC1z+kQ84jbaYb\n\tVfXwTqXVczZ+hNj36uDv70R7R/b64qvoIWlX4OGE=","Date":"Thu, 21 Oct 2021 05:10:50 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YXDMKn1LKCKYgfs9@pendragon.ideasonboard.com>","References":"<20211020154607.180161-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20211020154607.180161-4-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211020154607.180161-4-jeanmichel.hautbois@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 03/13] ipa: ipu3: awb: Use\n\tsaturation under 90%","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]