[libcamera-devel,v4,25/32] ipa: rkisp1: awb: Use frame context to fix gains calculations
diff mbox series

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

Commit Message

Laurent Pinchart Sept. 8, 2022, 1:41 a.m. UTC
The AWB statistics are computed after the ISP applies the colour gains.
This means that the red, green and blue means do not match the data
coming directly from the sensor, but are multiplied by the colour gains
that were used for the frame on which the statistics have been computed.
The AWB algorithm needs to take this into account when calculating the
colour gains for the next frame. Do so by dividing the means by the
gains that were applied to the frame, retrieved from the frame context.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/ipa/rkisp1/algorithms/awb.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Kieran Bingham Sept. 20, 2022, 11:19 p.m. UTC | #1
Quoting Laurent Pinchart via libcamera-devel (2022-09-08 02:41:53)
> The AWB statistics are computed after the ISP applies the colour gains.
> This means that the red, green and blue means do not match the data
> coming directly from the sensor, but are multiplied by the colour gains
> that were used for the frame on which the statistics have been computed.
> The AWB algorithm needs to take this into account when calculating the
> colour gains for the next frame. Do so by dividing the means by the
> gains that were applied to the frame, retrieved from the frame context.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/ipa/rkisp1/algorithms/awb.cpp | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp
> index bb0f6c27fc7d..b711e93b73ba 100644
> --- a/src/ipa/rkisp1/algorithms/awb.cpp
> +++ b/src/ipa/rkisp1/algorithms/awb.cpp
> @@ -207,6 +207,15 @@ void Awb::process(IPAContext &context,
>         double greenMean = 1.1636 * yMean - 0.4045 * cbMean - 0.7949 * crMean;
>         double blueMean = 1.1636 * yMean + 1.9912 * cbMean - 0.0250 * crMean;
>  
> +       /*
> +        * The ISP computes the AWB means after applying the colour gains,
> +        * divide by the gains that were used to get the raw means from the
> +        * sensor.
> +        */
> +       redMean /= frameContext.awb.gains.red;
> +       greenMean /= frameContext.awb.gains.green;
> +       blueMean /= frameContext.awb.gains.blue;
> +

Sounds so easy now I see it in code.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

>         frameContext.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);
>  
>         /* Estimate the red and blue gains to apply in a grey world. */
> -- 
> Regards,
> 
> Laurent Pinchart
>
Jacopo Mondi Sept. 22, 2022, 10:25 a.m. UTC | #2
Hi Laurent

On Thu, Sep 08, 2022 at 04:41:53AM +0300, Laurent Pinchart via libcamera-devel wrote:
> The AWB statistics are computed after the ISP applies the colour gains.
> This means that the red, green and blue means do not match the data
> coming directly from the sensor, but are multiplied by the colour gains
> that were used for the frame on which the statistics have been computed.
> The AWB algorithm needs to take this into account when calculating the
> colour gains for the next frame. Do so by dividing the means by the
> gains that were applied to the frame, retrieved from the frame context.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Good catch!

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

Thanks
  j

> ---
>  src/ipa/rkisp1/algorithms/awb.cpp | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp
> index bb0f6c27fc7d..b711e93b73ba 100644
> --- a/src/ipa/rkisp1/algorithms/awb.cpp
> +++ b/src/ipa/rkisp1/algorithms/awb.cpp
> @@ -207,6 +207,15 @@ void Awb::process(IPAContext &context,
>  	double greenMean = 1.1636 * yMean - 0.4045 * cbMean - 0.7949 * crMean;
>  	double blueMean = 1.1636 * yMean + 1.9912 * cbMean - 0.0250 * crMean;
>
> +	/*
> +	 * The ISP computes the AWB means after applying the colour gains,
> +	 * divide by the gains that were used to get the raw means from the
> +	 * sensor.
> +	 */
> +	redMean /= frameContext.awb.gains.red;
> +	greenMean /= frameContext.awb.gains.green;
> +	blueMean /= frameContext.awb.gains.blue;
> +
>  	frameContext.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);
>
>  	/* Estimate the red and blue gains to apply in a grey world. */
> --
> Regards,
>
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp
index bb0f6c27fc7d..b711e93b73ba 100644
--- a/src/ipa/rkisp1/algorithms/awb.cpp
+++ b/src/ipa/rkisp1/algorithms/awb.cpp
@@ -207,6 +207,15 @@  void Awb::process(IPAContext &context,
 	double greenMean = 1.1636 * yMean - 0.4045 * cbMean - 0.7949 * crMean;
 	double blueMean = 1.1636 * yMean + 1.9912 * cbMean - 0.0250 * crMean;
 
+	/*
+	 * The ISP computes the AWB means after applying the colour gains,
+	 * divide by the gains that were used to get the raw means from the
+	 * sensor.
+	 */
+	redMean /= frameContext.awb.gains.red;
+	greenMean /= frameContext.awb.gains.green;
+	blueMean /= frameContext.awb.gains.blue;
+
 	frameContext.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);
 
 	/* Estimate the red and blue gains to apply in a grey world. */