[{"id":27637,"web_url":"https://patchwork.libcamera.org/comment/27637/","msgid":"<169079759132.4160537.13855341627615942951@Monstersaurus>","date":"2023-07-31T09:59:51","subject":"Re: [libcamera-devel] [PATCH 1/5] ipa: rpi: histogram: Add\n\tinterBinMean()","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting David Plowman via libcamera-devel (2023-07-31 10:46:37)\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/convertion/conversion/\n\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@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>         return first + frac;\n>  }\n>  \n> -double Histogram::interQuantileMean(double qLo, double qHi) const\n> +double Histogram::interBinMean(double binLo, double binHi) const\n>  {\n> -       assert(qHi > qLo);\n> -       double pLo = quantile(qLo);\n> -       double pHi = quantile(qHi, (int)pLo);\n> +       assert(binHi > binLo);\n>         double sumBinFreq = 0, cumulFreq = 0;\n> -       for (double pNext = floor(pLo) + 1.0; pNext <= ceil(pHi);\n> -            pLo = pNext, pNext += 1.0) {\n> -               int bin = floor(pLo);\n> +       for (double binNext = floor(binLo) + 1.0; binNext <= ceil(binHi);\n> +            binLo = binNext, binNext += 1.0) {\n> +               int bin = floor(binLo);\n>                 double freq = (cumulative_[bin + 1] - cumulative_[bin]) *\n> -                             (std::min(pNext, pHi) - pLo);\n> +                             (std::min(binNext, binHi) - binLo);\n>                 sumBinFreq += bin * freq;\n>                 cumulFreq += freq;\n>         }\n>         /* add 0.5 to give an average for bin mid-points */\n>         return sumBinFreq / cumulFreq + 0.5;\n>  }\n> +\n> +double Histogram::interQuantileMean(double qLo, double qHi) const\n> +{\n> +       assert(qHi > qLo);\n> +       double pLo = quantile(qLo);\n> +       double pHi = quantile(qHi, (int)pLo);\n> +       return 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>         uint64_t total() const { return cumulative_[cumulative_.size() - 1]; }\n>         /* Cumulative frequency up to a (fractional) point in a bin. */\n>         uint64_t cumulativeFreq(double bin) const;\n> +       /* Return the mean value between two (fractional) bins. */\n> +       double interBinMean(double binLo, double binHi) const;\n>         /*\n>          * Return the (fractional) bin of the point q (0 <= q <= 1) through the\n>          * 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 1FF45BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 31 Jul 2023 09:59:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 73B28627EB;\n\tMon, 31 Jul 2023 11:59:56 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3F1DA6037D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Jul 2023 11:59:54 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id ED1CB2E4;\n\tMon, 31 Jul 2023 11:58:51 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1690797596;\n\tbh=pnV1wvMXzq6nY2W/DiLD1YVKEVC6ixBUtYoOOPxoUjk=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=NjvIPYAPsgZJG3p3FMsDgY4dbB6R7Vpp5LzLT2YSsGlkHRPxtkUfCv2h/lg7b8vHs\n\tbjeZ8b4yGQNoeVvOFt+sSV4nma3S06DKHD4E/0dMLeoLUpmwDcf23pbMwdjogB9eH4\n\t4ZmNKx01DTNmGj6dhn5mRyD/0JJb/tlkn7vEGvyZ6230JkG94jT3HDMN/cOfCZo5Qp\n\tEZJcg1okGV3kIeMhbV81YIuYeFMrJhGMwf635q6qvD+uEtgYwktTs+AMrwpI2O2s+q\n\t0BBKubdewYBnlrxuflcKIXgEwKuq929OFwGliy+F4hWhJbmkkcXNoo8ideOyXOUQCy\n\txejy3BbDX+AxQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1690797532;\n\tbh=pnV1wvMXzq6nY2W/DiLD1YVKEVC6ixBUtYoOOPxoUjk=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=NfC6Gfr/H2kfymXAfoHoN1S95rhG7zt9IJWcdMRQgK/MkGJEdwrIi0VGOHkWqyN3H\n\twJEmUZHrWHG4rxPPb+EN/L66hteyQlrju0N+zRiyxYz3MCPJbyvfngwhBORXQ9SJEl\n\t8UyM9V50WGdYSNm3l9cPapeDDq77aYfEDlqF4lAw="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"NfC6Gfr/\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20230731094641.73646-2-david.plowman@raspberrypi.com>","References":"<20230731094641.73646-1-david.plowman@raspberrypi.com>\n\t<20230731094641.73646-2-david.plowman@raspberrypi.com>","To":"David Plowman <david.plowman@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 31 Jul 2023 10:59:51 +0100","Message-ID":"<169079759132.4160537.13855341627615942951@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH 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":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27638,"web_url":"https://patchwork.libcamera.org/comment/27638/","msgid":"<CAHW6GYJTqoLGdbh8iuQB7an8sPn7fNPQRZ3sTRW94-HvLX+y7A@mail.gmail.com>","date":"2023-07-31T11:48:00","subject":"Re: [libcamera-devel] [PATCH 1/5] ipa: rpi: histogram: Add\n\tinterBinMean()","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Actually also s/quatiles/quantiles/ !!\n\nI can send an update to this one (and add my own reviewed-by seeing as\nit's Naush's originally).\n\nDavid\n\nOn Mon, 31 Jul 2023 at 10:59, Kieran Bingham\n<kieran.bingham@ideasonboard.com> wrote:\n>\n> Quoting David Plowman via libcamera-devel (2023-07-31 10:46:37)\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> /convertion/conversion/\n>\n> >\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n>\n>\n> Reviewed-by: Kieran Bingham <kieran.bingham@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> >         return first + frac;\n> >  }\n> >\n> > -double Histogram::interQuantileMean(double qLo, double qHi) const\n> > +double Histogram::interBinMean(double binLo, double binHi) const\n> >  {\n> > -       assert(qHi > qLo);\n> > -       double pLo = quantile(qLo);\n> > -       double pHi = quantile(qHi, (int)pLo);\n> > +       assert(binHi > binLo);\n> >         double sumBinFreq = 0, cumulFreq = 0;\n> > -       for (double pNext = floor(pLo) + 1.0; pNext <= ceil(pHi);\n> > -            pLo = pNext, pNext += 1.0) {\n> > -               int bin = floor(pLo);\n> > +       for (double binNext = floor(binLo) + 1.0; binNext <= ceil(binHi);\n> > +            binLo = binNext, binNext += 1.0) {\n> > +               int bin = floor(binLo);\n> >                 double freq = (cumulative_[bin + 1] - cumulative_[bin]) *\n> > -                             (std::min(pNext, pHi) - pLo);\n> > +                             (std::min(binNext, binHi) - binLo);\n> >                 sumBinFreq += bin * freq;\n> >                 cumulFreq += freq;\n> >         }\n> >         /* add 0.5 to give an average for bin mid-points */\n> >         return sumBinFreq / cumulFreq + 0.5;\n> >  }\n> > +\n> > +double Histogram::interQuantileMean(double qLo, double qHi) const\n> > +{\n> > +       assert(qHi > qLo);\n> > +       double pLo = quantile(qLo);\n> > +       double pHi = quantile(qHi, (int)pLo);\n> > +       return 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> >         uint64_t total() const { return cumulative_[cumulative_.size() - 1]; }\n> >         /* Cumulative frequency up to a (fractional) point in a bin. */\n> >         uint64_t cumulativeFreq(double bin) const;\n> > +       /* Return the mean value between two (fractional) bins. */\n> > +       double interBinMean(double binLo, double binHi) const;\n> >         /*\n> >          * Return the (fractional) bin of the point q (0 <= q <= 1) through the\n> >          * 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 E5C7EBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 31 Jul 2023 11:48:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 14D64627E9;\n\tMon, 31 Jul 2023 13:48:13 +0200 (CEST)","from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com\n\t[IPv6:2607:f8b0:4864:20::f2f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 75A946037D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Jul 2023 13:48:12 +0200 (CEST)","by mail-qv1-xf2f.google.com with SMTP id\n\t6a1803df08f44-63d0f62705dso31564536d6.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Jul 2023 04:48:12 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1690804093;\n\tbh=xDtHiGsXSje/m11aBxJzIh0c+j736Vdh8GwwPBxCMno=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=oovfmGW6NdDvTkyK+E7FBu3SNM/z7WXGIfwWDSrxb27D9ZQl1k+ByB8kDQHWupypM\n\tcrEFV7H1xkvPckcA3TtbqBh0yqXsU81FIZMUaitS6oZyambTHlYW67N4K2H3Ptvirq\n\tOnIJV8h/9nKA1v3ZsFHIkV2ysd8ACPskU3DfOmFJSNRMgzS9jVedQpyb4cuPpJ35Hi\n\tp8MVlSbIw61PkLQOgYGApPFley1hlVhr3YHsiPzVRmbDcW5h/JS+NWYIDLG2l0Ut+K\n\t35WiXH0cz3D47tZWczOQdvhz1dJ5tNKsIiHnr7JnPBdCtEbuhUVVksF1pAS64GKp3z\n\t9dhABxbrThF/A==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1690804091; x=1691408891;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=480D6K/HGHDZ9eZVZ7NsF37xWRWNKeMh9AwoTVUxb5I=;\n\tb=C+svBxncbsb9Dk4NKAaGDL6aw4hy7wnUu9btZGcdACzZeo16llYLaDsPNl3ahjnTYy\n\t23YTm4gChk8V8zahGMvTTJNq2vj/IBQ2MCga3o1mwV435st8iJpQ9hMJPIIGKLZrpaCB\n\tqwt24ap3vHUikbmoZJdUhqnFpdKcGWTgJsrVH5fPZ/Ytch25kOjerhvUWzS0BEHCaJ5p\n\tDHyC5ffm0dhJgfoHShO+4ltSXzZwlwM3RZfoqn5Y+2ofzrdnakux9J1OMn/AC7Zu0TJp\n\tyqaC0EWeE430XgZtr7nsczJ6E1Q9Y+7NnpyVADe9ZeFhkPOgX6IjZ2Zhn0fB31EYd0pO\n\tbmqg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"C+svBxnc\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1690804091; x=1691408891;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=480D6K/HGHDZ9eZVZ7NsF37xWRWNKeMh9AwoTVUxb5I=;\n\tb=P378BM5Q5OWxG40QQ4IAn7HzuRPAv6rq0OX3TzhMv7ykLKw0AfU2os7GX8ifT7UJOw\n\tBr3lSApt1P3EHANDrhx50wPDRPIHEowUD73IuCbiE9yWIj6EVD9m6Hh2eRiB94kfNPv2\n\tWqhk0eN+jDVfkDPTdFGoA0kPC/kAQ6X3hs8egZPlsViiPiMHvYjR0rEvk+e66bcQUzbS\n\t+36BGKbmHWwH58MfgWusnJfXfDZ6gEXKFzRJcJoeSDSYhosTAJhzszTQEV7cOiSspyOR\n\tA7Al5BN4VBY8cVaymS/UQX739kO5Kp0q8AB1HMXaU6AZQxJboQNdQJCrEsZ/0GuKrvxU\n\tlA3w==","X-Gm-Message-State":"ABy/qLbvbAN2TOgdCCC83w+MmGr+9tujNmJ/NUBFeTLJJem1GCHLXGps\n\tnS3TtoWEqpOWKIZbYYS76uI3viMP1a0ie5CeGXBJllvTcI74M2dj","X-Google-Smtp-Source":"APBJJlFSu+yIr/0dJTG7Ba+Yr2BfTytsvftkVCMAtLks55qXOO+zVNGC7d7vsNjpesuhNArd9BxZUkY35fUA/h6YUN8=","X-Received":"by 2002:a05:6214:2b8e:b0:630:7d0:56f4 with SMTP id\n\tkr14-20020a0562142b8e00b0063007d056f4mr9761493qvb.49.1690804091263;\n\tMon, 31 Jul 2023 04:48:11 -0700 (PDT)","MIME-Version":"1.0","References":"<20230731094641.73646-1-david.plowman@raspberrypi.com>\n\t<20230731094641.73646-2-david.plowman@raspberrypi.com>\n\t<169079759132.4160537.13855341627615942951@Monstersaurus>","In-Reply-To":"<169079759132.4160537.13855341627615942951@Monstersaurus>","Date":"Mon, 31 Jul 2023 12:48:00 +0100","Message-ID":"<CAHW6GYJTqoLGdbh8iuQB7an8sPn7fNPQRZ3sTRW94-HvLX+y7A@mail.gmail.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH 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":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]