[{"id":27709,"web_url":"https://patchwork.libcamera.org/comment/27709/","msgid":"<ovk7um7fomlq4jzkr7ufbo4fdyihgg3346rrbsgx7sphjsgqbo@siq6aav3sq2h>","date":"2023-08-29T15:18:30","subject":"Re: [libcamera-devel] [PATCH v2 1/5] ipa: rpi: histogram: Add\n\tinterBinMean()","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi David\n\nOn Wed, Aug 23, 2023 at 01:09:11PM +0100, David Plowman via libcamera-devel wrote:\n> From: Naushir Patuck <naush@raspberrypi.com>\n>\n> Add a new helper function Histogram::interBinMean() that essentially\n> replaces the existing Histogram::interQuantileMean() logic but working on\n> bins instead.\n>\n> Rework the interQuantileMean() to call into interBinMean() with the\n> appropriate convertion from quatiles to bins.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\n> ---\n>  src/ipa/rpi/controller/histogram.cpp | 22 ++++++++++++++--------\n>  src/ipa/rpi/controller/histogram.h   |  2 ++\n>  2 files changed, 16 insertions(+), 8 deletions(-)\n>\n> diff --git a/src/ipa/rpi/controller/histogram.cpp b/src/ipa/rpi/controller/histogram.cpp\n> index 16a9207f..0a27ba2c 100644\n> --- a/src/ipa/rpi/controller/histogram.cpp\n> +++ b/src/ipa/rpi/controller/histogram.cpp\n> @@ -45,20 +45,26 @@ double Histogram::quantile(double q, int first, int last) const\n>  \treturn first + frac;\n>  }\n>\n> -double Histogram::interQuantileMean(double qLo, double qHi) const\n> +double Histogram::interBinMean(double binLo, double binHi) const\n>  {\n> -\tassert(qHi > qLo);\n> -\tdouble pLo = quantile(qLo);\n> -\tdouble pHi = quantile(qHi, (int)pLo);\n> +\tassert(binHi > binLo);\n>  \tdouble sumBinFreq = 0, cumulFreq = 0;\n> -\tfor (double pNext = floor(pLo) + 1.0; pNext <= ceil(pHi);\n> -\t     pLo = pNext, pNext += 1.0) {\n> -\t\tint bin = floor(pLo);\n> +\tfor (double binNext = floor(binLo) + 1.0; binNext <= ceil(binHi);\n> +\t     binLo = binNext, binNext += 1.0) {\n> +\t\tint bin = floor(binLo);\n>  \t\tdouble freq = (cumulative_[bin + 1] - cumulative_[bin]) *\n> -\t\t\t      (std::min(pNext, pHi) - pLo);\n> +\t\t\t      (std::min(binNext, binHi) - binLo);\n>  \t\tsumBinFreq += bin * freq;\n>  \t\tcumulFreq += freq;\n>  \t}\n>  \t/* add 0.5 to give an average for bin mid-points */\n>  \treturn sumBinFreq / cumulFreq + 0.5;\n>  }\n> +\n> +double Histogram::interQuantileMean(double qLo, double qHi) const\n> +{\n> +\tassert(qHi > qLo);\n> +\tdouble pLo = quantile(qLo);\n> +\tdouble pHi = quantile(qHi, (int)pLo);\n> +\treturn interBinMean(pLo, pHi);\n> +}\n> diff --git a/src/ipa/rpi/controller/histogram.h b/src/ipa/rpi/controller/histogram.h\n> index 6b3e3a9e..e2c5509b 100644\n> --- a/src/ipa/rpi/controller/histogram.h\n> +++ b/src/ipa/rpi/controller/histogram.h\n> @@ -38,6 +38,8 @@ public:\n>  \tuint64_t total() const { return cumulative_[cumulative_.size() - 1]; }\n>  \t/* Cumulative frequency up to a (fractional) point in a bin. */\n>  \tuint64_t cumulativeFreq(double bin) const;\n> +\t/* Return the mean value between two (fractional) bins. */\n> +\tdouble interBinMean(double binLo, double binHi) const;\n>  \t/*\n>  \t * Return the (fractional) bin of the point q (0 <= q <= 1) through the\n>  \t * histogram. Optionally provide limits to help.\n> --\n> 2.30.2\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 E48D1C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Aug 2023 15:18:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4046D627E0;\n\tTue, 29 Aug 2023 17:18:35 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D5C1261E02\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Aug 2023 17:18:33 +0200 (CEST)","from ideasonboard.com (mob-5-90-48-16.net.vodafone.it [5.90.48.16])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BC904B1;\n\tTue, 29 Aug 2023 17:17:11 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1693322315;\n\tbh=bcXw44zDNQQ645YEvBsao5ewIARolGHie3JkJL2muJ4=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=LPxzPPjRCyo3P1S1A45ODLZCyLc/uHMYhUmd4MheFP+F5d7mZRfzL7Ld2HD9EzCxD\n\tVM8DeLH7JThPiSYh55g9ibawJE8NVCbFILzPCG9voaG35GVnvTraEeU0Yz0jPqqzOe\n\t3+hjJj1vAv97pUZExpVreSBkvHbuBeX+iyTrpkIU383Z2Iq/bu8MwESBiosBcZeESj\n\tQBPhd6HnK+KaMp30zSvZ2EYXTm+zawX9EBVME8VNbtGxmDSJQY40ReYAF8vJXXsS0O\n\tm6T3R+yn63q/vQHBjgKtm4Z+a/8h3JEZki7ye3/N11AttrBp0MX13FqD9TyJ/lR7hn\n\tJTxmSsMxN17Pw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1693322231;\n\tbh=bcXw44zDNQQ645YEvBsao5ewIARolGHie3JkJL2muJ4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=EAMLWKGRlqcUUNOE0RuFBxVo8gNAcoZ39i2Fmb7iHRlKU4Er8kCWriDe5Wex+ylcl\n\txoFiNKtiVQZtDqrkz3hdD8IQZC4/bRu9cqNOExS+7+U9w06aL5unkpMFus4u3Bw6QT\n\t19SBFp1N6QAThCPPcQYGb4OXMjNbpBI5gvhcr5jg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"EAMLWKGR\"; dkim-atps=neutral","Date":"Tue, 29 Aug 2023 17:18:30 +0200","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<ovk7um7fomlq4jzkr7ufbo4fdyihgg3346rrbsgx7sphjsgqbo@siq6aav3sq2h>","References":"<20230823120915.18621-1-david.plowman@raspberrypi.com>\n\t<20230823120915.18621-2-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230823120915.18621-2-david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v2 1/5] ipa: rpi: histogram: Add\n\tinterBinMean()","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]