[libcamera-devel,v5,33/33] ipa: rkisp1: awb: Remove bias from gain calculation
diff mbox series

Message ID 20220927023642.12341-34-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • ipa: Frame context queue, IPU3 & RkISP consolidation, and RkISP1 improvements
Related show

Commit Message

Laurent Pinchart Sept. 27, 2022, 2:36 a.m. UTC
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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/ipa/rkisp1/algorithms/awb.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Jacopo Mondi Sept. 27, 2022, 9:21 a.m. UTC | #1
Hi Laurent

On Tue, Sep 27, 2022 at 05:36:42AM +0300, Laurent Pinchart via libcamera-devel wrote:
> 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 <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

> ---
>  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
> --
> Regards,
>
> Laurent Pinchart
>

Patch
diff mbox series

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