From patchwork Mon Jul 31 09:46:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 18905 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 9FB2CBDB13 for ; Mon, 31 Jul 2023 09:46:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B0C32627F0; Mon, 31 Jul 2023 11:46:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1690796807; bh=HZ1HQi8StWKq23YMtV9lNb7bvoOCR1720QDC6QcT1E4=; 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=czVGFZVfkn2M1WzwXQxABnpGA+vDtmn/Dq5Nlg4e3+QL9fIYtP7+Emmjyj2etHagn /pe5uonjVS6Oh9g0tTv7dtXJNajLoaaIg0JnfRFBsct8WP5MzQVZYsA6xMZRuJu5ii +KNpQiwovGZml+scMMo/4GdbpoPjcWUweEWCowlevUziJUtaClCoKWDOv7DpW2vyZP 8cgtdQxU3JyW+kqlVE1D0v73ZnfPJzAEDBx/jmz6LnybNaVx4xbE9hey1rvzC+JXS8 xibIY69VPH7DkaPgCjW15sibTavqJcInfoi8jabcvjmYAW3+SFduP3vOwmSNq/pucG TqM3601cHsFMA== Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4BE87627E8 for ; Mon, 31 Jul 2023 11:46:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="hhsezBFM"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fbc59de0e2so39781385e9.3 for ; Mon, 31 Jul 2023 02:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1690796805; x=1691401605; 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=h/HPCdJqCX5ZMO0JFYmakkAGInDV7AColVdgpVx0OUg=; b=hhsezBFMFwngZF4W960Rum1Q8bmouD8FXxuf/G+390DE2pGmiX+ph5OCd6n+NXjpKc pDfT3ZYz3E/uXY3ZEsQj29FTVSdzQfJdLClQazP2UDYL9HrQBbbTW/WkfqOFnY1FyNv1 zL4U2hAlRQn2t0RJYP9FgPH0mFszQS69aeMqCq1X7MU4V60Q5bMCrltPEShp1JTue1rt zIYNMwkll1Tj50pujL4QH46uSROCDtjb+BIi4L9sknXiVexmnE0Gw/k6qhmqsIxix3HV keLjPbb0n0N9ALPKHPRmGrhdPd+hDGGic8tqQpKMjkIPxn1Bup7a7/A8cRe27ApU9RNg djFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690796805; x=1691401605; 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=h/HPCdJqCX5ZMO0JFYmakkAGInDV7AColVdgpVx0OUg=; b=H2DUDY7iRtuXmVrqbgDv5T8HL8vbRzV7kzEiBOPnQ7giRI5YXpd39ZshuZxWM2tt3A 7HlqhI7h4B7cYx2H5ELc/tLXrdpeGmP707fNlEiYMT/tCGqLRXbeiGp5f1b4chqwxH1b M3u6HLRHwfO0SidrQBThxg+Lo3spzbFvUDT3+G9PuHNT87tE/hXZQSS8Ed1nSueO7LWS tnoXTqj3Vx14mhAHl1k+B345hVqS+hLDfegG4jg8SO36Hag8J8+BJ3YpwBw7P/7YpqMC wn4UnSNgmbzNsa8BGc1syaD3VF87esGzzAj23nKdh86soGHaZJ8m6COrXO7fo59zD09L S96g== X-Gm-Message-State: ABy/qLaA+sv8pdeK4fxLmrUnLjHpb4IOOt8YiKFzsI5ODWYgJq3BZbjs GqfSdMlcz7g79wsr/mt3GdIre00cfwUmQul0Xus= X-Google-Smtp-Source: APBJJlG12ndMc8bSFhB6u4TaelSaEt16AsSyxODEwjEYZZPdQ4WyHVCAnNbisUnBHyPipBZD32pgNw== X-Received: by 2002:a05:600c:2143:b0:3fe:2140:f504 with SMTP id v3-20020a05600c214300b003fe2140f504mr1396263wml.20.1690796804783; Mon, 31 Jul 2023 02:46:44 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:2bce:64d6:1a5c:49a2]) by smtp.gmail.com with ESMTPSA id 9-20020a05600c240900b003fa98908014sm13612838wmp.8.2023.07.31.02.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 02:46:44 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 31 Jul 2023 10:46:37 +0100 Message-Id: <20230731094641.73646-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230731094641.73646-1-david.plowman@raspberrypi.com> References: <20230731094641.73646-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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: Kieran Bingham --- 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.