From patchwork Fri Oct 22 15:12:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 14271 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 59725BF415 for ; Fri, 22 Oct 2021 15:12:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9826A68F73; Fri, 22 Oct 2021 17:12:31 +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="LwL1q0Tz"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A81EA6012A for ; Fri, 22 Oct 2021 17:12:23 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:22cc:3af6:5ccb:8367]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 70C7951D; Fri, 22 Oct 2021 17:12:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634915543; bh=fM0WX4vMyX+GX/z7liQZaGTy6MzFM2k6zjsOXSxQGy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LwL1q0Tzgw2zamxs/oTk62DwzPeJNawal+OY6SmDmhHGR8bWwLb+gTNLdWJql4ouP 7hdzk0Ev2ezirxOVmpFsv/UN9A/hbqJe0SZSOFCCT3sAbsMCoSgZBR6aKKBgVWwlYE LhfuBIXlENsk73h7cEYVhCCQJxJjOrcSiTXqzrHU= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Oct 2021 17:12:04 +0200 Message-Id: <20211022151218.111966-6-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211022151218.111966-1-jeanmichel.hautbois@ideasonboard.com> References: <20211022151218.111966-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 05/19] ipa: ipu3: awb: Add AWB class documentation 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 AWB algorithm is based on the Grey world algorithm and uses the statistics generated by the ImgU for that. Explain how it uses those, and reference the original algorithm at the same time. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- v3: - move the diagram from Accumulator to AWB - add a word to say green gains are always set to 1 --- src/ipa/ipu3/algorithms/awb.cpp | 108 ++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 41 deletions(-) diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index 91364a04..7e10460f 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -11,6 +11,10 @@ #include +/** + * \file awb.h + */ + namespace libcamera { namespace ipa::ipu3::algorithms { @@ -42,47 +46,6 @@ static constexpr uint32_t kMinCellsPerZoneRatio = 255 * 90 / 100; * \struct Accumulator * \brief RGB statistics for a given zone * - * - Cells are defined in Pixels - * - Zones are defined in Cells - * - * 80 cells - * /───────────── 1280 pixels ───────────\ - * 16 zones - * 16 - * ┌────┬────┬────┬────┬────┬─ ──────┬────┐ \ - * │Cell│ │ │ │ │ | │ │ │ - * 16 │ px │ │ │ │ │ | │ │ │ - * ├────┼────┼────┼────┼────┼─ ──────┼────┤ │ - * │ │ │ │ │ │ | │ │ - * │ │ │ │ │ │ | │ │ 7 - * │ ── │ ── │ ── │ ── │ ── │ ── ── ─┤ ── │ 1 2 4 - * │ │ │ │ │ │ | │ │ 2 0 5 - * - * │ │ │ │ │ │ | │ │ z p c - * ├────┼────┼────┼────┼────┼─ ──────┼────┤ o i e - * │ │ │ │ │ │ | │ │ n x l - * │ │ | │ │ e e l - * ├─── ───┼─ ──────┼────┤ s l s - * │ │ | │ │ s - * │ │ | │ │ - * ├─── Zone of Cells ───┼─ ──────┼────┤ │ - * │ (5 x 4) │ | │ │ │ - * │ │ | │ │ │ - * ├── ───┼─ ──────┼────┤ │ - * │ │ │ | │ │ │ - * │ │ │ │ │ │ | │ │ │ - * └────┴────┴────┴────┴────┴─ ──────┴────┘ / - * - * - * The algorithm works with a fixed number of zones \a kAwbStatsSizeX x - * \a kAwbStatsSizeY. For example, a frame of 1280x720 is divided into 80x45 - * cells of [16x16] pixels. In the case of \a kAwbStatsSizeX=16 and - * \a kAwbStatsSizeY=12 the zones are made of [5x4] cells. The cells are - * left-aligned and calculated by IPAIPU3::calculateBdsGrid(). - * - * Each statistics cell represents the average value of the pixels in that cell - * split by colour components. - * * The Accumulator structure stores the sum of the average of each cell in a * zone of the image, as well as the number of cells which were unsaturated and * therefore included in the average. @@ -152,6 +115,69 @@ static const struct ipu3_uapi_ccm_mat_config imguCssCcmDefault = { 0, 0, 8191, 0 }; +/** + * \class Awb + * \brief A Grey world white balance correction algorithm + * + * The Grey World algorithm assumes that the scene, in average, is neutral grey. + * Reference: Lam, Edmund & Fung, George. (2008). Automatic White Balancing in + * Digital Photography. 10.1201/9781420054538.ch10. + * + * The IPU3 generates statistics from the Bayer Down Scaler output into a grid + * defined in the ipu3_uapi_awb_config_s structure. + * + * - Cells are defined in Pixels + * - Zones are defined in Cells + * + * 80 cells + * /───────────── 1280 pixels ───────────\ + * 16 zones + * 16 + * ┌────┬────┬────┬────┬────┬─ ──────┬────┐ \ + * │Cell│ │ │ │ │ | │ │ │ + * 16 │ px │ │ │ │ │ | │ │ │ + * ├────┼────┼────┼────┼────┼─ ──────┼────┤ │ + * │ │ │ │ │ │ | │ │ + * │ │ │ │ │ │ | │ │ 7 + * │ ── │ ── │ ── │ ── │ ── │ ── ── ─┤ ── │ 1 2 4 + * │ │ │ │ │ │ | │ │ 2 0 5 + * + * │ │ │ │ │ │ | │ │ z p c + * ├────┼────┼────┼────┼────┼─ ──────┼────┤ o i e + * │ │ │ │ │ │ | │ │ n x l + * │ │ | │ │ e e l + * ├─── ───┼─ ──────┼────┤ s l s + * │ │ | │ │ s + * │ │ | │ │ + * ├─── Zone of Cells ───┼─ ──────┼────┤ │ + * │ (5 x 4) │ | │ │ │ + * │ │ | │ │ │ + * ├── ───┼─ ──────┼────┤ │ + * │ │ │ | │ │ │ + * │ │ │ │ │ │ | │ │ │ + * └────┴────┴────┴────┴────┴─ ──────┴────┘ / + * + * + * The algorithm works with a fixed number of zones \a kAwbStatsSizeX x + * \a kAwbStatsSizeY. For example, a frame of 1280x720 is divided into 80x45 + * cells of [16x16] pixels. In the case of \a kAwbStatsSizeX=16 and + * \a kAwbStatsSizeY=12 the zones are made of [5x4] cells. The cells are + * left-aligned and calculated by IPAIPU3::calculateBdsGrid(). + * + * Each statistics cell represents the average value of the pixels in that cell + * split by colour components. + * + * Before calculating the gains, we will convert the statistics from the BDS + * grid to an internal grid configuration in generateAwbStats. + * As part of converting the statistics to an internal grid, the saturation + * flag from the originating grid cell is used to decide if the zone contains + * saturated pixels or not, making the zone relevant or not. + * A saturated zone will be excluded from the calculation. + * + * The Grey World algorithm will then estimate the red and blue gains to apply, and + * store the results in the metadata. The green gain is always set to 1. + */ + Awb::Awb() : Algorithm() {