From patchwork Fri Sep 15 15:58:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 19034 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 929BBBD160 for ; Fri, 15 Sep 2023 15:58:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 49E7A6291D; Fri, 15 Sep 2023 17:58:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1694793532; bh=u61zsKeWhQAgxve5YcLlCpBT79AgLH4OcJpd3Ged9qE=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=RdQ3kdZm62NGOydpXRvlvgOKi0pZI2mlemQoTYksBWvjdfllz0+6NpxajqLOvVphh rNt4KYAKz2BhUBYWx+kjScIrLOp5DQ7Z4AqQ3aPaxm9SiWTfpWIRc1ZKxYmAdPg+p4 5NmYAIOuEltYKQFwhwFkxuRqdMC3x4rbtsM5AYGTeS+SwmlYefo+nR/wK9aA8JvlGu z3yR9U+7QpRtUwW3lptmeDISaRAI4oPDgXT1TyUr1tauwvZxvFilh9+epD+oDb+jEl /yp3tWrqW9fLxH81apQn6gOuHkOP+TQJNHgPxOLyHa/SKxp9zJsuev3FqaMwUEv08L nqPDzTprAIS5g== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 42DA9628EC for ; Fri, 15 Sep 2023 17:58:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="kes1vK9U"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40434d284f7so22809895e9.3 for ; Fri, 15 Sep 2023 08:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1694793530; x=1695398330; darn=lists.libcamera.org; 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=PLzIHdZWYnWfcoP1tg/UVALNkMV3EEqa5nrqb1B3Op8=; b=kes1vK9Ui66o6hXXzrZOvNZ+lnEQS5P97c48etkxv8ush37OpspghZBFk8+o2cutk0 8h/VHOcAnHIyUnDPyJahjmpHa+5CAiaQeQiaikDNJEq5e02H9q4of/hFxN35OfQm04am 3pjCjvr6Mf4nOSvq6HSTZO8IpMWun3ikIfAlRUWoKXfgyOXlRgMwhkTwlT/wPrb5ETNc eO3L8G2GP0jqKUfAc+X+GJzjKmarK+h7Q1e0rgGMF5A2s2VjLyyDUcNHEkRSSpgOE9CM fLqJHqFDDRuHytB238RTxX9AHlX7E6gH9g8QRh4p3BiPRt9UWGMZrnPysIPnwg7jJkjx ysHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694793530; x=1695398330; 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=PLzIHdZWYnWfcoP1tg/UVALNkMV3EEqa5nrqb1B3Op8=; b=tOXgX9T2pm1Ww1iHbc4dF6iOj6243OfgKU0LRhunuDe0IymI0c3RAP6G0KM4gpqqIw 5BAQag53qIgzp62LvmP1iqTwJBMTQdll2zLp8l8mfLxJUun739hyNVFMwN5zUIY+4j1R tH1kFEPYFhFWiKtYAst5ZOtWSdGOF1kGgGE2uiY+HKOqfz66ct8Zpf2eTL6iAevNeoCx If6rLqNGMPHwmiqE5TU0d0fRNbztbHN3sB/Dy/WpaKtsXmaHfBZ7LMnzyxt8JojY1eo0 5bFyO92HPuLRP0QRUpiqaRG8zLwTRFU/ixMGCoWkTVi1CaBhQRed/xaRpzCQ3GYJmnGt hNfA== X-Gm-Message-State: AOJu0Yx5bXY7eCQV8tIW1yITfcfyCJZnn46wemSl55tf1zqhNAYkAcjm VPSD29vVh36+GIoOh6N5q9GsiB1uwV5q9duHujU= X-Google-Smtp-Source: AGHT+IHRy+DMKozH3lm8b1nPEFOfpKKlhWRzDIxxODNP1GLolMLUmIObx6lEr3FTWwlkJWBORlLaRw== X-Received: by 2002:a7b:c4cb:0:b0:401:b53e:6c56 with SMTP id g11-20020a7bc4cb000000b00401b53e6c56mr2227815wmk.3.1694793530403; Fri, 15 Sep 2023 08:58:50 -0700 (PDT) Received: from localhost.localdomain ([195.180.61.40]) by smtp.gmail.com with ESMTPSA id l13-20020a7bc44d000000b00401c595fcc7sm7810618wmi.11.2023.09.15.08.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 08:58:47 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 15 Sep 2023 16:58:40 +0100 Message-Id: <20230915155844.2388-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230915155844.2388-1-david.plowman@raspberrypi.com> References: <20230915155844.2388-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Cc: Jacopo Mondi 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.