From patchwork Tue Sep 27 02:36:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17444 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 46C3BC0DA4 for ; Tue, 27 Sep 2022 02:37:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 12A5362383; Tue, 27 Sep 2022 04:37:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664246274; bh=cYsCTrk5122uifEVEu5V4F9/P4MluZ7OC+U6xLpN+uI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=z2P+FFyWiDso1Zpib7J/T9JY9f9XYuPkLUD0enXAdd0vca46meBPe3OAYx2phK2In i4DwPfZ4fz7GS7mA4FbHISZSRmy6zKCTLg8BpARkeGZ14/8sdTZNO5ctm0l54kWt6/ 0F+o4EMjMu86VVGSVFqE3pDy6+4TF3nScRusQY754FPK8FlVSOQzCc0olXoe9PdC96 lec4dBOWPqNeKL/qOAGGXcJ1CMOgmqVO5mOJ3We6FSynIBB0Z+FiBFdHACGNPdF/8m kwRClwUlDbUg4U5Hm6Cez7ghmb8GwNBtPX44LnvnllQa7AV15WdnvfEYe93cDe0b2i C1uMXRx8IEZOA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 18AE362369 for ; Tue, 27 Sep 2022 04:37:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cubKMqwS"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 88EA647C for ; Tue, 27 Sep 2022 04:37:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664246270; bh=cYsCTrk5122uifEVEu5V4F9/P4MluZ7OC+U6xLpN+uI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cubKMqwSV5fL98iiRR+XOsxi2zOe+EM5vebfPEhEA/o/2jBiQJsPGjDhRIwCLPKGY AYCXAJjMMDr6X2PaZ4F2IUpuyDP2My1Itoyb1/gqwsOjMZQdmrDuRmuNsA0OykEzGr z82hamIy1r9ilBuAJDkAA9o9e0ge7kTCclHUEMlc= To: libcamera-devel@lists.libcamera.org Date: Tue, 27 Sep 2022 05:36:42 +0300 Message-Id: <20220927023642.12341-34-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220927023642.12341-1-laurent.pinchart@ideasonboard.com> References: <20220927023642.12341-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 33/33] ipa: rkisp1: awb: Remove bias from gain calculation 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The red and blue gains are computed by dividing the green mean by the red and blue means respectively. An offset of 1 is added to the dividers to avoid divisions by zero. This introduces a bias in the gain values. Fix it by clamping the divisors to a minimum of 1.0 instead of adding an offset. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- src/ipa/rkisp1/algorithms/awb.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index eb32cd722071..3349948a3acf 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -280,10 +280,11 @@ void Awb::process(IPAContext &context, /* * Estimate the red and blue gains to apply in a grey world. The green - * gain is hardcoded to 1.0. + * gain is hardcoded to 1.0. Avoid divisions by zero by clamping the + * divisor to a minimum value of 1.0. */ - double redGain = greenMean / (redMean + 1); - double blueGain = greenMean / (blueMean + 1); + double redGain = greenMean / std::max(redMean, 1.0); + double blueGain = greenMean / std::max(blueMean, 1.0); /* * Clamp the gain values to the hardware, which expresses gains as Q2.8