From patchwork Fri Sep 15 12:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 19015 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 87DE2C3260 for ; Fri, 15 Sep 2023 12:30:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6179B62919; Fri, 15 Sep 2023 14:30:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1694781020; 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=VbOJBt9ZKGV0aDpSKMGXp5COOeoUZUNL8KD/pwfp9X8tUiTAkWkd6FOgQu1BG1y2g 5WdKFzfqVsIAahWC4avGfYhR1Ih2ZeDPayxG1j/AlNlQkspjkYYdk5W00grxeDdRLd 9KXGK0PjqdATwVTOX9/NnPK/lJcgTy5q4wZ9Lrrz0w8DJTbk26533zZh2TDWT3N5Jw ytex3TKOTmuNszw66ryK0yuDkkmIZBM+/xWA51whJ9nHSGkMalROSTyBjb50W+Kt4J Y7VQRb1VDMWQ6D6LEv72ububdTQJd1xT/vNe6Y/j1W2CLHY+y+h3EkV1at3+b8vVcs bF7ueqXKrtRaA== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1BF92628EC for ; Fri, 15 Sep 2023 14:30:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SvXU0nVs"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-31c4d5bd69cso1940619f8f.3 for ; Fri, 15 Sep 2023 05:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1694781018; x=1695385818; 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=SvXU0nVsahcUHIGNQnH32gB5pjFlIApW17UnlcbVgFuNXR5r8u04ASE464VqO1EqCL NmqLJqlCeRLsDveEzA7zMfxs830ntkr2iPoB8ip0f3t1KVY5cgmXxkcp8AkZV0XjaJUE PxMYgFHIauSbA002GvzSej+VWKHLM0/GwRHxZXUG8GCLJ3+RfV1P+fGt2jpvzwgpjHUf h5OfGY1cru36P/uKVw9Azx6Vw/tLiPcGoGgNruL2OIJ1XLS//HfLRlPZADPZYPRDWcqd M62CttBdY6a6KOxoT+ZBUiRST+BzinugHdQw1RH5oeZtRf9xtBR9xvKc9XrRZcIOh9mo 7dzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694781018; x=1695385818; 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=D5KT6G8s56eoZErNNX2gL5QA+4i1UjfNp5+K/kFdedH7Qot8k1+VJFjausyfmed2zV yJqUaUsu8al5AdqGK8+T2p9XTfqP10YOFL3DmF7vzXrvmp3mEfPxsFnmiaH45jAM30xN FltLkF3W2mhKkGSHqIRDLw/w8R/V7U5SmOqifaM+5cnqMIYUkGV4pL3oKheD0OH8GgcG BE74iacytK5nahZ0uXDKGuQxII/RFzWbTrbJ6dqlFvm1sFrhxKBdRsvW3bWVvBpTe/Dz gQd0DHJnLnyEUWeN4AeLcm1EfArhR5+DfmTt2BE2hmU9nazjXYuTQOA2V+9D2/DwIAm6 DeNA== X-Gm-Message-State: AOJu0YwcCY3JawcPIRDbTzuGHlJxrrYEqb+I1xP52418wNphQ6nXCd0q Jr+EDUgvIJu7XvC5463F0GwN3s08ghj3wOKlAn4= X-Google-Smtp-Source: AGHT+IGWP0SCZsawPPRxtRFsagd+4oy9i6PbS60fJ4uAQClQ+CZUzzcxS80EEQ9/oROytyMGYvi2DQ== X-Received: by 2002:a5d:6a4c:0:b0:317:3a18:df26 with SMTP id t12-20020a5d6a4c000000b003173a18df26mr1370899wrw.39.1694781018357; Fri, 15 Sep 2023 05:30:18 -0700 (PDT) Received: from localhost.localdomain ([195.180.61.40]) by smtp.gmail.com with ESMTPSA id y14-20020a7bcd8e000000b004030e8ff964sm7435009wmj.34.2023.09.15.05.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:30:17 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 15 Sep 2023 13:29:50 +0100 Message-Id: <20230915122954.5231-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230915122954.5231-1-david.plowman@raspberrypi.com> References: <20230915122954.5231-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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.