From patchwork Wed Dec 6 17:27:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Hollinghurst X-Patchwork-Id: 19293 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 5CD3BC32BC for ; Wed, 6 Dec 2023 17:27:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BE33B62B31; Wed, 6 Dec 2023 18:27:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1701883670; bh=1RB6+g4qfDW8rnb7Ja0vIUciQE5tC+vClsItg7uobb8=; 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=1nm4refd+TMAheu3h/dY/dodptkr1yfgvfI5/FNPLbZXzJ1EtbVr7wgQDkRYjMuLF r8+YTEF9SWym8YWMybSzqDoLcFYAKdO7mwX193fjv/fKEsFaMdvsU4sIdS5cwWO3dY HFkPA1iOXdYUMVA6gOQBmyWfFG+HD0piNtM4Io6Ta6N7kMpPSGn/WpHNhrPlWO0E7+ Tv8vms3FmIVCdAoCM8BEKtAv7RTptjEFXxy9wZsXkvaX4U+hwtH3O1ko8tOg9uVTxP 5sf5bysQeueYEnoRqJLJ9kJe54P5H/gX03l1mCa/qDA4aQ3VIBRMiEc2xDKwZwxyuI WXgD1v1UcOzfg== Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 863BC61D9E for ; Wed, 6 Dec 2023 18:27:48 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="T3wPslu+"; dkim-atps=neutral Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3332f1512e8so25262f8f.2 for ; Wed, 06 Dec 2023 09:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1701883668; x=1702488468; 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=aZhuqx7wWBWMSOCJUTftNWGOyTmgbVHIYfBu+U4mHcA=; b=T3wPslu+Q7BxuLwmm46wl5LDgW6S2IlVUBC4iljt4DlX0xAoNfdLQBWjUYE0wXK7q8 F8zGRaHHJ/rzbTpbNUcACkarc+FaKTRjEnN6mKxWISCTZ7p9tN8jAn/DgxIHknMwZyrm KFvp7x+ZYbJn6FRveuFr1mitiTRH2vpIDvekmYiK7oQ5v3Y2i24fHUV+dJe3XQ8aWtFH o7eX2AjB9Qs4A18vuQvW89woA/i8tTlc3ZZ1LlO5hV+fDCPFjyT9uUV1h4sRTPoKALJA pB2fNbsKEryzKVfkrgOZ8heoFAPsZ5YhY9vFMeJQKkLGwC/b4qCm9/maXA+f1pl7g0E1 9PRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701883668; x=1702488468; 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=aZhuqx7wWBWMSOCJUTftNWGOyTmgbVHIYfBu+U4mHcA=; b=upbUxT8IbAx8CDp6rZsWp/saJNmuToTvFUaEy8zPUIP6WY2T4wY7kNH1sUm0TnJ9py WdK5FqwtyHhC5vqmzZ0VYx+EKozPebZb1XkmaSLDZLY6hbaQicnZYHeHAGqk9D/A4Djz Bz6kYEhsWFdUrPogaHC+CZ60G3lsnxBLgx9cIfGpNRJ5cNlbh3iSK/S9J/XyuKO4GL8q Eo94T9P+DU+cfXNwWSPY8TNh5IjDIcxaERsp0E+oFj6puoSqIECGFbehiNo+udmb0MxU uw3zzAkgihK4fKIsd6QhnpsTX7zQ55qWKoDChbvSEODaSkRhQNiitu0K1m1Y2m4okRnd FFFg== X-Gm-Message-State: AOJu0YwDDzJD3kIy246RgTd1GuedTVhC7ku3tk/s6bbpHk3f1kS2qkQ7 Du+mCqDwB2IKMl0J6fUyTRL1j14T5B2Sr5NqjncvLQ== X-Google-Smtp-Source: AGHT+IG1zTIqX0B5UCHoC3kJaRNUoUJGyGkWkMXY+2MAqoJFIHaeUGTMyFSdCFmUa/gIZIoOrfJRdQ== X-Received: by 2002:a5d:4fc5:0:b0:333:3fc7:f2bf with SMTP id h5-20020a5d4fc5000000b003333fc7f2bfmr728856wrw.134.1701883667965; Wed, 06 Dec 2023 09:27:47 -0800 (PST) Received: from raspberrypi.pitowers.org ([2001:4d4e:300:1f:e6dd:75ca:a054:1499]) by smtp.gmail.com with ESMTPSA id s9-20020a5d4ec9000000b003334898aafasm190515wrv.11.2023.12.06.09.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 09:27:47 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Dec 2023 17:27:43 +0000 Message-Id: <20231206172743.13355-2-nick.hollinghurst@raspberrypi.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231206172743.13355-1-nick.hollinghurst@raspberrypi.com> References: <20231206172743.13355-1-nick.hollinghurst@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] ipa: rpi: Allow the mean of an empty histogram interval 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: Nick Hollinghurst via libcamera-devel From: Nick Hollinghurst Reply-To: Nick Hollinghurst Cc: Nick Hollinghurst Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Don't assert when taking the weighted mean of a zero-width or zero-weight interval; return its upper bound. That is certainly correct in the zero-width case, and plausible otherwise. Signed-off-by: Nick Hollinghurst Reviewed-by: David Plowman Reviewed-by: Naushir Patuck --- src/ipa/rpi/controller/histogram.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/controller/histogram.cpp b/src/ipa/rpi/controller/histogram.cpp index 0a27ba2c..78116141 100644 --- a/src/ipa/rpi/controller/histogram.cpp +++ b/src/ipa/rpi/controller/histogram.cpp @@ -47,7 +47,7 @@ double Histogram::quantile(double q, int first, int last) const double Histogram::interBinMean(double binLo, double binHi) const { - assert(binHi > binLo); + assert(binHi >= binLo); double sumBinFreq = 0, cumulFreq = 0; for (double binNext = floor(binLo) + 1.0; binNext <= ceil(binHi); binLo = binNext, binNext += 1.0) { @@ -57,13 +57,19 @@ double Histogram::interBinMean(double binLo, double binHi) const sumBinFreq += bin * freq; cumulFreq += freq; } + + if (cumulFreq == 0) { + /* interval had zero width or contained no weight? */ + return binHi; + } + /* 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); + assert(qHi >= qLo); double pLo = quantile(qLo); double pHi = quantile(qHi, (int)pLo); return interBinMean(pLo, pHi);