From patchwork Wed Aug 23 12:09:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 18951 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id ABBA7C3262 for ; Wed, 23 Aug 2023 12:09:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 09076627DF; Wed, 23 Aug 2023 14:09:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1692792562; bh=VC872qSQmTIHBHsNVEBK4zhptjsHyXIelDczVsln2+4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=y9BjaHAzkEGnQsHXniBovUFjUDub1/p++Rt3uDM31Q2WnK+kyrqeioHZamUu+v/C9 QqVBQ8vXD7NagDihsG7kCaJHDo33ksGwSiG5YD8vX4ceZRpr+33vkKHuMlLVPIq2PQ JCulKsgxnsnVURKEobiSyPYYUWYs+n6nLtxrK50XJCL/5iEUJBWZ3k9y6g338FYTS6 qUhSfQzO4dGRuUcizpbjnFFyBil5zkrDHyt8+dO1gmKyx0bXF+cPoDqcEkqB/dbckg Wsly8w70Q84+oBt+sY2gxx2wZmn5B8zewKQzcuddJJLt/KO8xz5TAhMgwBl35148/R DxZoArizYO1kg== Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 020A560379 for ; Wed, 23 Aug 2023 14:09:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="s3UX7Q5u"; dkim-atps=neutral Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-400a087b0bfso1483915e9.2 for ; Wed, 23 Aug 2023 05:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1692792559; x=1693397359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u7iKFr8D3j7b58GG5UKdV0vUoX70DBmLHHZQRY3Vb7Y=; b=s3UX7Q5uiuMaKza7evIjOaBBuBvaikpVGMwm719bP52Z7iw+oesfFYWMwl9J7vA39S pH5gcQY1ukuXFRlwDct4ndKvQMPvTGF3JZ+6nERpN1bpK7ADKewgDVs2hU81rqty3RYh 7T0rTL1IgLSp5oZUdoGg7IQc9tTGbhbqhsUqlSi0P+pxHSKgqsdVpppSfZdqw/L8YDnt jsph99RBHZAm33IOa5mpF3OocD4Bu50HY1e+e/QCfTyvwk/Q8NzBv3UnkCEtt+6lXhfB mTr+DFcQbW/kP8nOhWk8RsVqpY8Ngtb+XrA9NdT0C8YBgavBKuPWx0DccJTph+dwCJov XEoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692792559; x=1693397359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u7iKFr8D3j7b58GG5UKdV0vUoX70DBmLHHZQRY3Vb7Y=; b=NgX+hJMrLm4jMEVmfjU3WUuzS5W1H/HfKBGz/u9rVOLAurIVFsFQKcTnrOOOLsXetk A6rOXgwD0ZsjdXA1862L/RLgXTk05QIcR+CP9wrdrhvZiRYhxmvPMa4AZzkuVK/9RAuz sMUepzmMl3qieyrFTA0ik3OE94C+B4aFquT5oRLvOeuDTbaOeM3cTI2DCFwp/I9UowPO 1i7Hkx+Elb8gyHDUC4sX1KjMwO1cs3stpCKrcy9h9DsZ0wUpRM3lW76ByAKsTgyiXyXC M1oP8NIB8FxNOlPrTggR8datcJ2ieBKmSb+Jumq2ngdR1CKq2BE7JncDxmuMuLpKZLHp TCRg== X-Gm-Message-State: AOJu0YwWGL9kkUHF0RgTU98DRfjorlMhDRCIWRpQFwBO5ksG2OxZPzg6 X4HGZUbqLURcu7jRggvlm3CoeM4LhlkfHt0Y+UI= X-Google-Smtp-Source: AGHT+IHK+5iGBnSJUn36Yv2dlGlKUTsseI0Hur4wG0Z76cgmyh4Y1hb9Ec6r7ti9Q8qkr+HAbEFF1g== X-Received: by 2002:a05:600c:2307:b0:3fe:1cac:37d5 with SMTP id 7-20020a05600c230700b003fe1cac37d5mr9871084wmo.4.1692792559221; Wed, 23 Aug 2023 05:09:19 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:2bce:64d6:1a5c:49a2]) by smtp.gmail.com with ESMTPSA id u1-20020a7bcb01000000b003fefcbe7fa8sm3800589wmj.28.2023.08.23.05.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 05:09:18 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Aug 2023 13:09:11 +0100 Message-Id: <20230823120915.18621-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230823120915.18621-1-david.plowman@raspberrypi.com> References: <20230823120915.18621-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/5] ipa: rpi: histogram: Add interBinMean() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Naushir Patuck Add a new helper function Histogram::interBinMean() that essentially replaces the existing Histogram::interQuantileMean() logic but working on bins instead. Rework the interQuantileMean() to call into interBinMean() with the appropriate convertion from quatiles to bins. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/ipa/rpi/controller/histogram.cpp | 22 ++++++++++++++-------- src/ipa/rpi/controller/histogram.h | 2 ++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ipa/rpi/controller/histogram.cpp b/src/ipa/rpi/controller/histogram.cpp index 16a9207f..0a27ba2c 100644 --- a/src/ipa/rpi/controller/histogram.cpp +++ b/src/ipa/rpi/controller/histogram.cpp @@ -45,20 +45,26 @@ double Histogram::quantile(double q, int first, int last) const return first + frac; } -double Histogram::interQuantileMean(double qLo, double qHi) const +double Histogram::interBinMean(double binLo, double binHi) const { - assert(qHi > qLo); - double pLo = quantile(qLo); - double pHi = quantile(qHi, (int)pLo); + assert(binHi > binLo); double sumBinFreq = 0, cumulFreq = 0; - for (double pNext = floor(pLo) + 1.0; pNext <= ceil(pHi); - pLo = pNext, pNext += 1.0) { - int bin = floor(pLo); + for (double binNext = floor(binLo) + 1.0; binNext <= ceil(binHi); + binLo = binNext, binNext += 1.0) { + int bin = floor(binLo); double freq = (cumulative_[bin + 1] - cumulative_[bin]) * - (std::min(pNext, pHi) - pLo); + (std::min(binNext, binHi) - binLo); sumBinFreq += bin * freq; cumulFreq += freq; } /* add 0.5 to give an average for bin mid-points */ return sumBinFreq / cumulFreq + 0.5; } + +double Histogram::interQuantileMean(double qLo, double qHi) const +{ + assert(qHi > qLo); + double pLo = quantile(qLo); + double pHi = quantile(qHi, (int)pLo); + return interBinMean(pLo, pHi); +} diff --git a/src/ipa/rpi/controller/histogram.h b/src/ipa/rpi/controller/histogram.h index 6b3e3a9e..e2c5509b 100644 --- a/src/ipa/rpi/controller/histogram.h +++ b/src/ipa/rpi/controller/histogram.h @@ -38,6 +38,8 @@ public: uint64_t total() const { return cumulative_[cumulative_.size() - 1]; } /* Cumulative frequency up to a (fractional) point in a bin. */ uint64_t cumulativeFreq(double bin) const; + /* Return the mean value between two (fractional) bins. */ + double interBinMean(double binLo, double binHi) const; /* * Return the (fractional) bin of the point q (0 <= q <= 1) through the * histogram. Optionally provide limits to help.