[{"id":20973,"web_url":"https://patchwork.libcamera.org/comment/20973/","msgid":"<YZPUFaVJZ/LVzndV@pendragon.ideasonboard.com>","date":"2021-11-16T15:53:57","subject":"Re: [libcamera-devel] [PATCH v2] ipa: ipu3: agc: Remove the\n\tthreshold for the histogram calculation","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 Tue, Nov 16, 2021 at 04:24:44PM +0100, Jean-Michel Hautbois wrote:\n> Until commit f8f07f9468c6 (ipa: ipu3: agc: Improve gain calculation)\n> the gain to apply on the exposure value was only using the histogram.\n> Now that the global brightness of the frame is estimated too, we don't\n> need to remove part of the saturated pixels from the equation anymore.\n> \n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> v2: - remove the empty histogram test\n>     - don't take Kieran's R-B tag as it needs testing again\n> \n> ---\n>  src/ipa/ipu3/algorithms/agc.cpp | 32 +++++++++-----------------------\n>  1 file changed, 9 insertions(+), 23 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index 4e424857..bd02c474 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n> @@ -58,12 +58,6 @@ 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>  /* Number of frames to wait before calculating stats on minimum exposure */\n>  static constexpr uint32_t kNumStartupFrames = 10;\n>  \n> @@ -133,27 +127,19 @@ void Agc::measureBrightness(const ipu3_uapi_stats_3a *stats,\n>  \t\t\t\t\t&stats->awb_raw_buffer.meta_data[cellPosition]\n>  \t\t\t\t);\n>  \n> -\t\t\tif (cell->sat_ratio <= kMinCellsPerZoneRatio) {\n> -\t\t\t\tuint8_t gr = cell->Gr_avg;\n> -\t\t\t\tuint8_t gb = cell->Gb_avg;\n> -\t\t\t\t/*\n> -\t\t\t\t * Store the average green value to estimate the\n> -\t\t\t\t * brightness. Even the overexposed pixels are\n> -\t\t\t\t * taken into account.\n> -\t\t\t\t */\n> -\t\t\t\thist[(gr + gb) / 2]++;\n> -\t\t\t}\n> +\t\t\tuint8_t gr = cell->Gr_avg;\n> +\t\t\tuint8_t gb = cell->Gb_avg;\n> +\t\t\t/*\n> +\t\t\t * Store the average green value to estimate the\n> +\t\t\t * brightness. Even the overexposed pixels are\n> +\t\t\t * taken into account.\n> +\t\t\t */\n> +\t\t\thist[(gr + gb) / 2]++;\n>  \t\t}\n>  \t}\n>  \n> -\tHistogram cumulativeHist = Histogram(Span<uint32_t>(hist));\n>  \t/* Estimate the quantile mean of the top 2% of the histogram */\n> -\tif (cumulativeHist.total() == 0) {\n> -\t\t/* Force the value as histogram is empty */\n> -\t\tiqMean_ = knumHistogramBins - 0.5;\n> -\t} else {\n> -\t\tiqMean_ = cumulativeHist.interQuantileMean(0.98, 1.0);\n> -\t}\n> +\tiqMean_ = Histogram(Span<uint32_t>(hist)).interQuantileMean(0.98, 1.0);\n>  }\n>  \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 878ACBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 Nov 2021 15:54:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 08F806032C;\n\tTue, 16 Nov 2021 16:54:23 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 41E2F60120\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Nov 2021 16:54:21 +0100 (CET)","from pendragon.ideasonboard.com\n\t(117.145-247-81.adsl-dyn.isp.belgacom.be [81.247.145.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CD30B547;\n\tTue, 16 Nov 2021 16:54:20 +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=\"bIsQfr75\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637078060;\n\tbh=PleEImr1rBnnxSi/QVehwrv6ncp6sOqBUqieS9xPp+8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=bIsQfr75FZzhKhiZuziGBAK6M7UdElwShv5iw6ptGRnFm/VwEE84CCKo1n/DHzyVU\n\tEPtgNfeQK4pqIlCRR/mZ/XlIQpAEpm+Ndx5BZEkSlcPVqptKF88zYLRVmvylC/9ytn\n\tzex1z37paSv5tapmEsQsJ6XGSYIgLRTOagblWDRo=","Date":"Tue, 16 Nov 2021 17:53:57 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YZPUFaVJZ/LVzndV@pendragon.ideasonboard.com>","References":"<20211116152443.56512-1-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211116152443.56512-1-jeanmichel.hautbois@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2] ipa: ipu3: agc: Remove the\n\tthreshold for the histogram calculation","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>"}},{"id":20974,"web_url":"https://patchwork.libcamera.org/comment/20974/","msgid":"<163707886762.3997548.2693820685551505853@Monstersaurus>","date":"2021-11-16T16:07:47","subject":"Re: [libcamera-devel] [PATCH v2] ipa: ipu3: agc: Remove the\n\tthreshold for the histogram calculation","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-16 15:24:44)\n> Until commit f8f07f9468c6 (ipa: ipu3: agc: Improve gain calculation)\n> the gain to apply on the exposure value was only using the histogram.\n> Now that the global brightness of the frame is estimated too, we don't\n> need to remove part of the saturated pixels from the equation anymore.\n> \n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n> v2: - remove the empty histogram test\n>     - don't take Kieran's R-B tag as it needs testing again\n\nRetested. No issues/blackouts on covered lens. Copes with backlights.\n\nI can certainly see the small subtle changes when the brightness is\nchanged by covering a backlight - but I don't think there's anything\ninappropriate there.\n\nTested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n>  src/ipa/ipu3/algorithms/agc.cpp | 32 +++++++++-----------------------\n>  1 file changed, 9 insertions(+), 23 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index 4e424857..bd02c474 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n> @@ -58,12 +58,6 @@ 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>  /* Number of frames to wait before calculating stats on minimum exposure */\n>  static constexpr uint32_t kNumStartupFrames = 10;\n>  \n> @@ -133,27 +127,19 @@ void Agc::measureBrightness(const ipu3_uapi_stats_3a *stats,\n>                                         &stats->awb_raw_buffer.meta_data[cellPosition]\n>                                 );\n>  \n> -                       if (cell->sat_ratio <= kMinCellsPerZoneRatio) {\n> -                               uint8_t gr = cell->Gr_avg;\n> -                               uint8_t gb = cell->Gb_avg;\n> -                               /*\n> -                                * Store the average green value to estimate the\n> -                                * brightness. Even the overexposed pixels are\n> -                                * taken into account.\n> -                                */\n> -                               hist[(gr + gb) / 2]++;\n> -                       }\n> +                       uint8_t gr = cell->Gr_avg;\n> +                       uint8_t gb = cell->Gb_avg;\n> +                       /*\n> +                        * Store the average green value to estimate the\n> +                        * brightness. Even the overexposed pixels are\n> +                        * taken into account.\n> +                        */\n> +                       hist[(gr + gb) / 2]++;\n>                 }\n>         }\n>  \n> -       Histogram cumulativeHist = Histogram(Span<uint32_t>(hist));\n>         /* Estimate the quantile mean of the top 2% of the histogram */\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> +       iqMean_ = Histogram(Span<uint32_t>(hist)).interQuantileMean(0.98, 1.0);\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 14596BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 Nov 2021 16:07:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 45A1460376;\n\tTue, 16 Nov 2021 17:07:51 +0100 (CET)","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 1A96C60120\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Nov 2021 17:07:50 +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 ACAD6E7;\n\tTue, 16 Nov 2021 17:07:49 +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=\"v6GMu7VP\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637078869;\n\tbh=6y+2R1Sv9seW8tACC+2ZhRGPapB85XXWjA8aFVs6sBw=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=v6GMu7VPxOTj/vCfrROW+zP8ns/ld9+F8OQThnFKL/tAGTnlXiexIzlpXiLCP0RwF\n\tDrswcvCFtmyCI1mUcdpzKx2E0swypVo8Q+koaxrtCM/1DRcltDnh7ORQve2wJvII92\n\t4BsaHiHefGvwi0ANNGaPQzTsZEG3QK/iRgA80NTU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211116152443.56512-1-jeanmichel.hautbois@ideasonboard.com>","References":"<20211116152443.56512-1-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":"Tue, 16 Nov 2021 16:07:47 +0000","Message-ID":"<163707886762.3997548.2693820685551505853@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v2] ipa: ipu3: agc: Remove the\n\tthreshold for the histogram calculation","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>"}}]