From patchwork Tue Oct 8 08:13:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21532 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 C02EEBD80A for ; Tue, 8 Oct 2024 08:13:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B3B5D63537; Tue, 8 Oct 2024 10:13:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Avlsvkxg"; dkim-atps=neutral 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 37C6A62C8E for ; Tue, 8 Oct 2024 10:13:28 +0200 (CEST) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-37d371840efso91f8f.3 for ; Tue, 08 Oct 2024 01:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1728375207; x=1728980007; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=pT1XzziQ0sR/LBkzMPdWZArxo/iYlN07w1b9fXTe5o0=; b=Avlsvkxg53mSf+MqvqxcFeKmx8eInmeBvkRknRZbj54898RWOZVmacKU/+jTyRDf6y CWV3e42U8WOVssl+KCwhCKwmIQNG3C7AeCbWodNSj5CvE6PIhbbONVq0IiwsR+lrkkdc K7NvKOtgm3bjKsK4ThCWP7HB19Kbu4MP1wNcpgV4B3YWcM09B8w5AWpK+a+V8lIwgaw2 N2/vqKnzjD3xXBst0Zb7ZcCXcoChJxQY3EIbFhlXLgB0rte6g2ROMNR/HQTGZjcQQ+wX L2WforiTpB2x2cpsHn1Xr+72NUfxkaG0DYG80gNgRexBrtIlg9llzEnSXVLnWFUGhtY+ vx2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728375207; x=1728980007; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pT1XzziQ0sR/LBkzMPdWZArxo/iYlN07w1b9fXTe5o0=; b=ODqhpZ7SlJHOwT0wRSxPHy+4Jmek37avCnYJ5sXl2jLFYAQWP0QyFUvSzoO1jMTooc uO8gsrlBY6Npkw3B6iIwVnu2n5mB4bzuxthALw3EoGwLCzQUtf1rHJRyQi1cqX98Bk+x uZVsDgBuAizEEDiwJehEXKvY6DQKtGnmp/1eYDYJvQeWMp4HvNFCJhWAgsHSIhOov1Hg EkIAldigs8Lfp5jYyjSwlCX0Pw0b72h8U4yDEHQcLa7SVBHMouIaGZORWrr/5tFUG3ni YpMhJ5pWsuQWxFEFlWs3Qn5Fe1aObJmCdHoH+DGjTPf5/bfvsAz3Iqewwf90yBkDN7VQ AlAA== X-Gm-Message-State: AOJu0YyLsMcnemA92ycJ4TvrnpAMpMlPocsN9VBlhJtC9CUesM8hIP/S qN9EHeqgNEO7zLLbgGky/08SQCZw4MOLxHdROtJHjmtMQEoDNXk5h47AN3YoJpjdu/K35D9B3ZT 8 X-Google-Smtp-Source: AGHT+IHnODnGqQCehHs3xiRSygzegT/3LQgP2MhxZ9Ac8WEudjpTvTKXF7iJFIetEi3X0jCZHLFIfQ== X-Received: by 2002:a5d:5887:0:b0:374:c2ce:eb1e with SMTP id ffacd0b85a97d-37d0e7d66aamr4329684f8f.8.1728375207313; Tue, 08 Oct 2024 01:13:27 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d1695e62bsm7492587f8f.81.2024.10.08.01.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 01:13:26 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , David Plowman , Laurent Pinchart Subject: [PATCH v3 1/2] ipa: rpi: awb: Add a const for the default colour temperature Date: Tue, 8 Oct 2024 09:13:16 +0100 Message-Id: <20241008081317.24602-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 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 e5d51092605e..65416d05b28e 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -21,6 +21,8 @@ using namespace libcamera; LOG_DEFINE_CATEGORY(RPiAwb) +constexpr double kDefaultCT = 4500.0; + #define NAME "rpi.awb" /* @@ -215,7 +217,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 = kDefaultCT; syncResults_.gainR = syncResults_.gainG = syncResults_.gainB = 1.0; } prevSyncResults_ = syncResults_; @@ -717,7 +719,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 = kDefaultCT; asyncResults_.gainR = gainR; asyncResults_.gainG = 1.0; asyncResults_.gainB = gainB; From patchwork Tue Oct 8 08:13:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21533 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 C3A57BD80A for ; Tue, 8 Oct 2024 08:13:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2DDA46353A; Tue, 8 Oct 2024 10:13:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="swTBWijK"; dkim-atps=neutral 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 ADA6463537 for ; Tue, 8 Oct 2024 10:13:28 +0200 (CEST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-42e6dbc8c7dso8783345e9.1 for ; Tue, 08 Oct 2024 01:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1728375208; x=1728980008; 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=I7AR8ICqltR9rP3dW1XPHYWeiKNlWZkRhiTUDjh6+Z0=; b=swTBWijKyYWFr5H2KUTX4PbQx5Fe/eGqiUODMBgj06KugFN9je5KQjtbl5paIJmNuu 7NPAXqIiAdvctU3Byy7/elAm705Cbl+IkCkLdZ7Ho4jfCce+OHOgwvkB0u0x6hfvZWlI opLg7zpsIXkqcGpGSleCtxK6UZpGyWtRHByYCoaQ+HeEtjyjqiU41B1f25omlgctN/b/ eQ8NupnN53LRCqurv1E4sAk5AxnK+mgObhEcSnU8cl05WFSZPMik0bakH8P1/kCOMklD DIb8UfsvPRFB9aook/VbgmjOucjsbIazDezTTgGipAhCQhSSzRDlRsZZ6Rlg/QPYEitO UwTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728375208; x=1728980008; 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=I7AR8ICqltR9rP3dW1XPHYWeiKNlWZkRhiTUDjh6+Z0=; b=CXKi6/zQXRWRZj6BiyV+eJw8Th7yl67l/izmfQ5SSJ2XxoCcRmDM22WoW29qTQZm37 I3KP/fh3GHf+9/jn4jmltdh2zBPU4T3w4VL4urnOgzU4xuiWFUZyA+nYnQihCgbuSzXC ZhSwcD62mfWQrLvn+fRYMwaWOJaU1dwgttcbtNIlR3lyRbVDwOXnf3VuGhfxxwWGVRO7 DYHK3vur5FqlFnDXx4JDv6ETlQz+bkeZFJJUMtH6i1xBZCnANL1d+wOg6OahiQk3JR2f 7LUtLuwMYYJbfTGT3feOb2TSCcDfmQHZfVcFkwEIMsEEs9FauX2KlTeNnyFA5F+qEf2m AGNw== X-Gm-Message-State: AOJu0YzqYN23LB7ZVgrbMjAl88qMVoPegCLGOLohCflNN4IRBN5yue9d cRovEeXCXAbhv7HGK4V3siNhnUHj2Jo19/my8136Tw7GD3zVylSBORzXfN1OX3PYXx2QuClbYqc n X-Google-Smtp-Source: AGHT+IEBGTY7H3EwirD41jf8M+t2LuwQ0w2FAewn+Ciy3NGMBh5awZijX607HLcAqYY/Vv56C+IAtA== X-Received: by 2002:a05:600c:1390:b0:42c:bb35:b6d0 with SMTP id 5b1f17b1804b1-42f85aa361cmr48594995e9.1.1728375207946; Tue, 08 Oct 2024 01:13:27 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d1695e62bsm7492587f8f.81.2024.10.08.01.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 01:13:27 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , David Plowman Subject: [PATCH v3 2/2] ipa: rpi: awb: Add a bias to the AWB search Date: Tue, 8 Oct 2024 09:13:17 +0100 Message-Id: <20241008081317.24602-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008081317.24602-1-naush@raspberrypi.com> References: <20241008081317.24602-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 Reviewed-by: Kieran Bingham --- 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 65416d05b28e..9d8e170d1bfe 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -170,6 +170,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(kDefaultCT); return 0; } @@ -410,7 +418,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); @@ -423,6 +432,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) { @@ -443,7 +460,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