[{"id":20719,"web_url":"https://patchwork.libcamera.org/comment/20719/","msgid":"<163638353128.275423.12543407051199755244@Monstersaurus>","date":"2021-11-08T14:58:51","subject":"Re: [libcamera-devel] [PATCH 04/22] ipa: ipu3: agc: Limit the\n\tnumber of saturated cells","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Jean-Michel Hautbois (2021-11-08 13:13:32)\n> When the histogram is calculated, we check if a cell is saturated or not\n> before cumulating its green value. This is wrong, and it can lead to an\n> empty histogram in case of a fully saturated frame.\n> \n> Use a constant to limit the amount of pixels within a cell before\n> considering it saturated. If at the end of the loop we still have an\n> empty histogram, then make it a fully saturated one.\n> \n> Bug: https://bugs.libcamera.org/show_bug.cgi?id=84\n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n>  src/ipa/ipu3/algorithms/agc.cpp | 16 ++++++++++++++--\n>  1 file changed, 14 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index b5d736c1..2bf68e04 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n> @@ -63,6 +63,12 @@ static constexpr uint32_t knumHistogramBins = 256;\n>  /* Target value to reach for the top 2% of the histogram */\n>  static constexpr double kEvGainTarget = 0.5;\n>  \n> +/*\n> + * Maximum ratio of saturated pixels in a cell for the cell to be considered\n> + * non-saturated and counted by the AGC algorithm.\n> + */\n> +static constexpr uint32_t kMinCellsPerZoneRatio = 255 * 20 / 100;\n> +\n>  Agc::Agc()\n>         : frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s),\n>           minExposureLines_(0), maxExposureLines_(0), filteredExposure_(0s),\n> @@ -124,7 +130,7 @@ void Agc::measureBrightness(const ipu3_uapi_stats_3a *stats,\n>                                         &stats->awb_raw_buffer.meta_data[cellPosition]\n>                                 );\n>  \n> -                       if (cell->sat_ratio == 0) {\n> +                       if (cell->sat_ratio <= kMinCellsPerZoneRatio) {\n>                                 uint8_t gr = cell->Gr_avg;\n>                                 uint8_t gb = cell->Gb_avg;\n>                                 /*\n> @@ -137,8 +143,14 @@ void Agc::measureBrightness(const ipu3_uapi_stats_3a *stats,\n>                 }\n>         }\n>  \n> +       Histogram cumulativeHist = Histogram(Span<uint32_t>(hist));\n>         /* Estimate the quantile mean of the top 2% of the histogram */\n> -       iqMean_ = Histogram(Span<uint32_t>(hist)).interQuantileMean(0.98, 1.0);\n> +       if (cumulativeHist.total() == 0) {\n> +               /* Force the value as histogram is empty */\n> +               iqMean_ = knumHistogramBins - 0.5;\n> +       } else {\n> +               iqMean_ = cumulativeHist.interQuantileMean(0.98, 1.0);\n> +       }\n\nI wondered if this logic should go in the Histogram itself, but I think\nit might be use case specific whether to fill artificially at the top or\nbottom, or otherwise - so this is probably the best way to handle this.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n>  }\n>  \n>  /**\n> -- \n> 2.32.0\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 3AEEBBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  8 Nov 2021 14:58:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3E81060369;\n\tMon,  8 Nov 2021 15:58:55 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C3E16032C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Nov 2021 15:58:54 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 14CAF9FF;\n\tMon,  8 Nov 2021 15:58:54 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"rZhnXfzp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1636383534;\n\tbh=IirzmPNERVWBJnGf49/T0ya7by6MkfWe+bcNHBBYMag=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=rZhnXfzpfEoRVZL9HGHKkZuIxuLX8ljsDAjjMVK7hpTsoLy1lWMlzTfx3bamKyxHR\n\tXd/19TX01sSbpdQcBL5Ps/OFVVWm025D/DguhMcUsHJrGImZg+sOaMVc5WdHnjJk+u\n\tX2v/kg9+LaaOBsbu+8LLILsklVenNPi3IbJkSKKc=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211108131350.130665-5-jeanmichel.hautbois@ideasonboard.com>","References":"<20211108131350.130665-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20211108131350.130665-5-jeanmichel.hautbois@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 08 Nov 2021 14:58:51 +0000","Message-ID":"<163638353128.275423.12543407051199755244@Monstersaurus>","User-Agent":"alot/0.9.1","Subject":"Re: [libcamera-devel] [PATCH 04/22] ipa: ipu3: agc: Limit the\n\tnumber of saturated cells","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>"}}]