From patchwork Tue Sep 12 10:24:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 18990 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 0EFB9C3260 for ; Tue, 12 Sep 2023 10:24:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BF5A9628EB; Tue, 12 Sep 2023 12:24:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1694514290; 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=mOQJMy1SAQ6aGGQES1D0BdcxhvdSoQETBChIkBXLuPrVVzrMu8OfCSTHgyyjAkIaB bSu/7MyDmD7ae6XZrS4H+qy/DqrGFcs+/QzDfflEBKL81Ai7/H1s1Kugvm6CvfSBhj JryHWi0/XDio+8UREQXHx1yrLH+g02CoRy84KfOoA/y0/ky4AWno1CJFf9IyoNgwNg aapsebjLvla5bxT7pUQGY9bB8oZKDmuv8TGsCofCrpxViiyl2L+SiaXTwzOGqd66vf Ll3xY+fhiIe25H63K+D3LFsfESeVhaS6nt4UnhVK7G2DAAN+BuNw0l3OkGiFZtra1x gNUaECZz2U0VQ== Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B642261DF5 for ; Tue, 12 Sep 2023 12:24:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ZqOtJnXq"; dkim-atps=neutral Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-401187f8071so34649575e9.0 for ; Tue, 12 Sep 2023 03:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1694514289; x=1695119089; 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=ZqOtJnXq27bqmullABTCillBFVq+PgRekiWzUQPA9/73Ja6/AUaGnjzBdWys7D1Mnv nguIEzNQVZr9fJypbKSsqG6EEAmrv0k5q0sw50Zyj5wj8Znid4VhKQoKC/J7+d781HDL D6RoRLN1x4gAyDAH1thZQAUGVUi+cXmJfJl6lmD8R3af+bqmEi74WjgGtEHUMtR5yHbu RglGeLBhMfsLTB7r9I1vJep4uQjUuFMBSuUm3V9FNtViJh6iexMaxpPwrUSsJiryNouA EJn7HxG+zEnL1H/94dO8tZlpZuJzp8g0yl8jSCXwdribiWW/SJ7xU/dCARpWuWmc08Vl Tn2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694514289; x=1695119089; 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=tD92C6sChdD3w2ZsO0Pvin+LWCA6LA0pQ3s/+qZ82f+hc73uBbTX33uYKfQqSHzGdg 3f4mBh4bChmsOPVxNggq3/EuXj8kE2Fg00InRL7gOlGTySEKPrDWhnrCh9P5yNhQ0L4r Z3ZItxOREb+28Ta3E7DdqzYpj4FKxJg/D0z3v0jV8YaIXHn3CIJo4Vp0Puh1CmjSJKMc smmUCi4i2aUUT9kqCwydo37gY9PzzZj1CRiWXnEsua7J4db1ONS9k/his4LW35tLO7DX eGEPhQI9uIpPKBnADrGHCOC/XMVGsqd/Nr7FL5ukqyMAYAISh7tbw/YtV2zi+HgV6ea0 Iyvw== X-Gm-Message-State: AOJu0Yw7SnNcNM7DXy9HDcotnoCV4boT44plj2rwqYgEG2lNfNpVeakS mYpHl1ssQZhPweIC0WfF5Kx9DNEfGXKBx89pOXY= X-Google-Smtp-Source: AGHT+IGA1/dF52bpUR8gI4eoeqLslap1LQdCuGOxKX0wVJ9uFAz/oHq3cjLGey5aQeMQbqz743/v2A== X-Received: by 2002:a1c:4c09:0:b0:3ff:516b:5c4c with SMTP id z9-20020a1c4c09000000b003ff516b5c4cmr1522718wmf.18.1694514289040; Tue, 12 Sep 2023 03:24:49 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:2bce:64d6:1a5c:49a2]) by smtp.gmail.com with ESMTPSA id n10-20020a05600c294a00b003fefaf299b6sm12426575wmd.38.2023.09.12.03.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:24:48 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 12 Sep 2023 11:24:38 +0100 Message-Id: <20230912102442.169001-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230912102442.169001-1-david.plowman@raspberrypi.com> References: <20230912102442.169001-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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.