From patchwork Mon Aug 23 12:49:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 13437 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 43D64BD87D for ; Mon, 23 Aug 2021 12:49:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3FB646891B; Mon, 23 Aug 2021 14:49:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SFcXRnCn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 19E27688A2 for ; Mon, 23 Aug 2021 14:49:43 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:b920:776:a08c:1d1f]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B3015DEF; Mon, 23 Aug 2021 14:49:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1629722982; bh=VWhok++3B0jlwziB2rCBoWl/dG/OOAP3G17I8TEEInM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SFcXRnCnwE9T8inqwD6zuEoSYnY21zkJA2zKER4k3TR7gVTmkF896sbkPo1z8VD1N l0GHzPqqGy/lWzp7pfVaeJZm7YYMyuECLB9mkxgGLij809xsXRbdlcB5k4BAYPJqu7 bblyXaJl/KUZ10p0Kh2WhoCGak5QfCwUAJ6gZyR4= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Aug 2021 14:49:32 +0200 Message-Id: <20210823124937.253539-3-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823124937.253539-1-jeanmichel.hautbois@ideasonboard.com> References: <20210823124937.253539-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 2/7] ipa: ipu3: awb: Correct the relevant zones proportion 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" The algorithm uses the statistics of a cell only if there is not too much saturated pixels in it. The grey world algorithm works fine when there are a limited number of outliers. Consider a valid zone to be at least 80% of unsaturated cells in it. This value could very well be configurable, and make the algorithm more or less tolerant. Signed-off-by: Jean-Michel Hautbois --- src/ipa/ipu3/algorithms/awb.cpp | 15 ++++++++++++--- src/ipa/ipu3/algorithms/awb.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index e05647c9..9497a21b 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -17,8 +17,6 @@ namespace ipa::ipu3::algorithms { LOG_DEFINE_CATEGORY(IPU3Awb) -static constexpr uint32_t kMinZonesCounted = 16; -static constexpr uint32_t kMinGreenLevelInZone = 32; /** * \struct IspStatsRegion @@ -114,6 +112,9 @@ static const struct ipu3_uapi_ccm_mat_config imguCssCcmDefault = { 0, 0, 8191, 0 }; +/* Minimum level of green in a given zone */ +static constexpr uint32_t kMinGreenLevelInZone = 16; + Awb::Awb() : Algorithm() { @@ -123,6 +124,7 @@ Awb::Awb() asyncResults_.temperatureK = 4500; zones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY); + minZonesCounted_ = 0; } Awb::~Awb() = default; @@ -163,7 +165,7 @@ void Awb::generateZones(std::vector &zones) for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) { RGB zone; double counted = awbStats_[i].counted; - if (counted >= kMinZonesCounted) { + if (counted >= minZonesCounted_) { zone.G = awbStats_[i].gSum / counted; if (zone.G >= kMinGreenLevelInZone) { zone.R = awbStats_[i].rSum / counted; @@ -181,6 +183,13 @@ void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats, uint32_t regionWidth = round(grid.width / static_cast(kAwbStatsSizeX)); uint32_t regionHeight = round(grid.height / static_cast(kAwbStatsSizeY)); + /* + * It is the minimum proportion of pixels counted within AWB region + * for it to be relevant. + * \todo This proportion could be configured. + */ + minZonesCounted_ = (regionWidth * regionHeight) * 80 / 100; + /* * Generate a (kAwbStatsSizeX x kAwbStatsSizeY) array from the IPU3 grid which is * (grid.width x grid.height). diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h index 332652d0..95238b6a 100644 --- a/src/ipa/ipu3/algorithms/awb.h +++ b/src/ipa/ipu3/algorithms/awb.h @@ -84,6 +84,7 @@ private: std::vector zones_; IspStatsRegion awbStats_[kAwbStatsSizeX * kAwbStatsSizeY]; AwbStatus asyncResults_; + uint32_t minZonesCounted_; }; } /* namespace ipa::ipu3::algorithms */