[10/10] ipa: rkisp1: awb: Avoid division by zero
diff mbox series

Message ID 20250217100203.297894-11-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • Some rkisp1 awb improvements
Related show

Commit Message

Stefan Klug Feb. 17, 2025, 10:01 a.m. UTC
As the gains can also be specified manually, the regulation can run
into numeric instabilities by dividing by near zero. Mitigate that by applying a small minium value.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 src/ipa/rkisp1/algorithms/awb.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Kieran Bingham Feb. 17, 2025, 12:24 p.m. UTC | #1
Quoting Stefan Klug (2025-02-17 10:01:51)
> As the gains can also be specified manually, the regulation can run
> into numeric instabilities by dividing by near zero. Mitigate that by applying a small minium value.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>

This sounds like a reasonable protection.

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

> ---
>  src/ipa/rkisp1/algorithms/awb.cpp | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp
> index 66e6aecedc4c..6315d2adaad9 100644
> --- a/src/ipa/rkisp1/algorithms/awb.cpp
> +++ b/src/ipa/rkisp1/algorithms/awb.cpp
> @@ -310,9 +310,9 @@ void Awb::process(IPAContext &context,
>         /*
>          * 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.
> +        * sensor. Apply a minimum value to avoid divisions by near-zero.
>          */
> -       rgbMeans /= frameContext.awb.gains;
> +       rgbMeans /= frameContext.awb.gains.max(0.01);
>  
>         /*
>          * If the means are too small we don't have enough information to
> -- 
> 2.43.0
>

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp
index 66e6aecedc4c..6315d2adaad9 100644
--- a/src/ipa/rkisp1/algorithms/awb.cpp
+++ b/src/ipa/rkisp1/algorithms/awb.cpp
@@ -310,9 +310,9 @@  void Awb::process(IPAContext &context,
 	/*
 	 * 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.
+	 * sensor. Apply a minimum value to avoid divisions by near-zero.
 	 */
-	rgbMeans /= frameContext.awb.gains;
+	rgbMeans /= frameContext.awb.gains.max(0.01);
 
 	/*
 	 * If the means are too small we don't have enough information to