From patchwork Thu Oct 3 08:02:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21495 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 8778CBD80A for ; Thu, 3 Oct 2024 08:02:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C10D46352D; Thu, 3 Oct 2024 10:02:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="USMEPEZK"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DD1A963522 for ; Thu, 3 Oct 2024 10:02:13 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42cb1866c8fso798215e9.3 for ; Thu, 03 Oct 2024 01:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727942533; x=1728547333; 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=mnstXQUMSR691E+q3p5F12M0QAneWP2DnnxLh2/apK0=; b=USMEPEZKSI6izwH+H0SzPvMh+F5s6EIOz50+u/BVy6qC+0nbQCeVPMujiTfmt4KGyr Sr5lxS+7iBd4L5UgigTdOZPosezm8Poi8nW27GCpOeTcOO4CJbzHrFOgkqGJlmkkuryu 6NL3s0QaJYTSbtbA56/S3UJlNi189ZIixa/Ph+EV+51DHRLsk3ndDzWxdgXLh8ndHjTc J6aezpRESKuMQVrwgtsaFoULtwbWmAPBDhFsENuvm3C5h/jLit/U7p48zLouue7srRz4 zd41gFjT2+qauQK3im2RhRFqMiqfLp6MwIR2wONvajhVvVAu0lg++MvurozlV0f6sArB +3ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727942533; x=1728547333; 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=mnstXQUMSR691E+q3p5F12M0QAneWP2DnnxLh2/apK0=; b=oR/P5XTa3WfvQluOp9n3SESGH1ojXWr3XT4LQfXIAdiT/VgC6m7uMYIxfrNtin9uAT WFEyAtaQpPGZ8tYoHpVPw7H4DtBoqu0bgdhCevkTNrjZ373Nsu0EKcp6G62cnYsT9C6Z q6CESblepZp+eIE+YyV/6BaPb/7pBWsm3WA3SZqiHFMqpfL6cMyC3JOIZ1DKzATuN7Dy H6x2rXuiJI0Z/7v48AxSAsM4XUKazPyOfRawq3kbw10bE9n2fXQ6Nb5UCpmNdoF0Af1H lttlxgiKqwNgTinjR+EP24icy8PMUQB6JOzMhISWBgq20qL7xFplY/7yoTbRfzypbwRG aMLA== X-Gm-Message-State: AOJu0Yw6TFQi2CEBdAGAFILY4JNWEbHqxu7TXehLb2+zYChSzYjJL+Cp k7yRRLT4N42vpqrAVBjWAy5bGeFiP8ZhIuErst0wBbut2UVOSTUTLZ5S3MrKfBCXpL3nSKmcl8G d X-Google-Smtp-Source: AGHT+IEz3L6/sUf4hhhXzoZiwbEuB3uSTD9NJ8Fgx9HDCXulQYz1RXBHRiBNgjIXe6s9FhMZdWIG8g== X-Received: by 2002:a05:600c:1d26:b0:42c:bfd6:9d1f with SMTP id 5b1f17b1804b1-42f777b010bmr21761855e9.1.1727942533047; Thu, 03 Oct 2024 01:02:13 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d082a6b69sm684952f8f.88.2024.10.03.01.02.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 01:02:12 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , David Plowman , Laurent Pinchart Subject: [PATCH v2 1/2] ipa: rpi: awb: Add a const for the default colour temperature Date: Thu, 3 Oct 2024 09:02:26 +0100 Message-Id: <20241003080228.25438-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003080228.25438-1-naush@raspberrypi.com> References: <20241003080228.25438-1-naush@raspberrypi.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" A default CT of 4500K is used in a couple of places. Add a constexpr value for the default CT value and use it instead. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/rpi/controller/rpi/awb.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp index f45525bce2d1..3904fed615f7 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -20,6 +20,8 @@ using namespace libcamera; LOG_DEFINE_CATEGORY(RPiAwb) +constexpr double DefaultCT = 4500.0; + #define NAME "rpi.awb" /* @@ -214,7 +216,7 @@ void Awb::initialise() syncResults_.gainB = 1.0 / config_.ctB.eval(syncResults_.temperatureK); } else { /* random values just to stop the world blowing up */ - syncResults_.temperatureK = 4500; + syncResults_.temperatureK = DefaultCT; syncResults_.gainR = syncResults_.gainG = syncResults_.gainB = 1.0; } prevSyncResults_ = syncResults_; @@ -716,7 +718,11 @@ void Awb::awbGrey() sumR += *ri, sumB += *bi; double gainR = sumR.G / (sumR.R + 1), gainB = sumB.G / (sumB.B + 1); - asyncResults_.temperatureK = 4500; /* don't know what it is */ + /* + * The grey world model can't estimate the colour temperature, use a + * default value. + */ + asyncResults_.temperatureK = DefaultCT; asyncResults_.gainR = gainR; asyncResults_.gainG = 1.0; asyncResults_.gainB = gainB; From patchwork Thu Oct 3 08:02:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21496 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 762CFC3263 for ; Thu, 3 Oct 2024 08:02:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D100763528; Thu, 3 Oct 2024 10:02:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="jSOa8Fyh"; dkim-atps=neutral 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 9D58E6351F for ; Thu, 3 Oct 2024 10:02:14 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-42f7e1fcb8dso988945e9.2 for ; Thu, 03 Oct 2024 01:02:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727942534; x=1728547334; 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=OF6k+gO/gUrGIO7nDwWvyOjqLkIrghDFrQyp/14hJlU=; b=jSOa8Fyh7AfE2rYA/3kuk+3GTqCepYYLVd0HGyo6kNRd5pBWpJoIlEwJ4dFsb4cLZ0 SKnNRSwXMt+VffNBu7nNJD7R1kngp35FBKKxqGhRQMLVL7Z9WXfAWsTbL9zqmLHDS4/M OuZNr6Xm1kDMF6Tc3eA6Yc/KeWC4ig+fJXb38GmOrm9mgXjXq3Mv2j8shgbbnw9Ox09S 1ibKyfL3l5Dqg55g1EddJBK9JXeVPGg91IXFmEJ3fijktk2XpreUS6ZEypx02bcDlIsu kJFAg1TeHSiLNMcotzUZV3+Ba/Fofy+TAa94BhaypTWhctiD5EQx9wRnkvyQpn1t9Mxc M1ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727942534; x=1728547334; 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=OF6k+gO/gUrGIO7nDwWvyOjqLkIrghDFrQyp/14hJlU=; b=CPRR0rIl5HY2pkcSyjbcHrTfT/31dguc7ocgpTcgESAGI8a6whfJuedzkPaSLDfPUK Cngu/rt2WJA2kvtOjO/K5LsnY6PTQsC1evv6iWeiJHQ5r1I3rz6J/Bmet3057zH5MLJc kxGuIHHlygbghOl7BhbKYLPc2i4yLb8Il4Fxw/Vm2aFvGKGHwLDc9tO3nz4dOIxl4VKU VlyHNSSKj89L2UrEMDDRo8OupRlDaIrqv8GTd0A4oPYlRZRMLJZtGZp+hCxKnW7KuLFX 7G6NSJsw5PJs/fhQ9QQfC8vPXV1n+DmVjS3dkOvkTt3mKMg3xHmoZm4BC4G9SwNbSrkw Z4nA== X-Gm-Message-State: AOJu0Yy/OackCYL3Y7MnIg76ii41lNxvLYPRVL8uv3uHHCtMCsT4uEP8 rHnvjty9FBZ3fYDszixaq5kVWRH/4JBGGU4L6CrttD77qZSrlokpp4OqMqWSpoRQFFr5+eqUWeq 6 X-Google-Smtp-Source: AGHT+IH8vG90nBXVuCn1eLbIat36oVHe9/n/o8GU8agxBwrATTvtzmBqwtVV3xBskPqiDH5bGAywgg== X-Received: by 2002:a5d:5f82:0:b0:374:c92b:80a0 with SMTP id ffacd0b85a97d-37cfb8b6267mr2096649f8f.3.1727942533707; Thu, 03 Oct 2024 01:02:13 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d082a6b69sm684952f8f.88.2024.10.03.01.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 01:02:13 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , David Plowman Subject: [PATCH v2 2/2] ipa: rpi: awb: Add a bias to the AWB search Date: Thu, 3 Oct 2024 09:02:27 +0100 Message-Id: <20241003080228.25438-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003080228.25438-1-naush@raspberrypi.com> References: <20241003080228.25438-1-naush@raspberrypi.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In the case of an AWB search failure, the current algorithm logic will return a point on the CT curve closest to where the search finisned. This can be quite undesirable. Instead, add some bias params to the AWB algorithm which will direct the search to a set CT value in the case where statistics become unreliable causing the search to fail. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- src/ipa/rpi/controller/rpi/awb.cpp | 23 +++++++++++++++++++++-- src/ipa/rpi/controller/rpi/awb.h | 4 ++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp index 3904fed615f7..2ab405ef395a 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -169,6 +169,14 @@ int AwbConfig::read(const libcamera::YamlObject ¶ms) whitepointB = params["whitepoint_b"].get(0.0); if (bayes == false) sensitivityR = sensitivityB = 1.0; /* nor do sensitivities make any sense */ + /* + * The biasProportion parameter adds a small proportion of the counted + * pixles to a region biased to the biasCT colour temperature. + * + * A typical value for biasProportion would be between 0.05 to 0.1. + */ + biasProportion = params["bias_proportion"].get(0.0); + biasCT = params["bias_ct"].get(DefaultCT); return 0; } @@ -409,7 +417,8 @@ void Awb::asyncFunc() static void generateStats(std::vector &zones, StatisticsPtr &stats, double minPixels, - double minG, Metadata &globalMetadata) + double minG, Metadata &globalMetadata, + double biasProportion, double biasCtR, double biasCtB) { std::scoped_lock l(globalMetadata); @@ -422,6 +431,14 @@ static void generateStats(std::vector &zones, continue; zone.R = region.val.rSum / region.counted; zone.B = region.val.bSum / region.counted; + /* + * Add some bias samples to allow the search to tend to a + * bias CT in failure cases. + */ + const unsigned int proportion = biasProportion * region.counted; + zone.R += proportion * biasCtR; + zone.B += proportion * biasCtB; + zone.G += proportion * 1.0; /* Factor in the ALSC applied colour shading correction if required. */ const AlscStatus *alscStatus = globalMetadata.getLocked("alsc.status"); if (stats->colourStatsPos == Statistics::ColourStatsPos::PreLsc && alscStatus) { @@ -442,7 +459,9 @@ void Awb::prepareStats() * any LSC compensation. We also ignore config_.fast in this version. */ generateStats(zones_, statistics_, config_.minPixels, - config_.minG, getGlobalMetadata()); + config_.minG, getGlobalMetadata(), + config_.biasProportion, config_.ctR.eval(config_.biasCT), + config_.ctB.eval(config_.biasCT)); /* * apply sensitivities, so values appear to come from our "canonical" * sensor. diff --git a/src/ipa/rpi/controller/rpi/awb.h b/src/ipa/rpi/controller/rpi/awb.h index ab30f4fa51c1..5d628b47c8a6 100644 --- a/src/ipa/rpi/controller/rpi/awb.h +++ b/src/ipa/rpi/controller/rpi/awb.h @@ -87,6 +87,10 @@ struct AwbConfig { double whitepointR; double whitepointB; bool bayes; /* use Bayesian algorithm */ + /* proportion of counted samples to add for the search bias */ + double biasProportion; + /* CT target for the search bias */ + double biasCT; }; class Awb : public AwbAlgorithm