[libcamera-devel] ipa: rpi: alsc: Do not allow zero colour ratio statistics
diff mbox series

Message ID 20231122091302.550574-1-david.plowman@raspberrypi.com
State Accepted
Commit 2fae9603e6cc483d9d0d74868721b272776513cf
Headers show
Series
  • [libcamera-devel] ipa: rpi: alsc: Do not allow zero colour ratio statistics
Related show

Commit Message

David Plowman Nov. 22, 2023, 9:13 a.m. UTC
The algorithm computes R/G and B/G colour ratio statistics which we
should not allow to go to zero because there is clearly no gain you
could apply to R or B to equalise them. Instead flag such regions as
having "insufficient data" in the normal manner.

Signed-off-by: David Plowman
---
 src/ipa/rpi/controller/rpi/alsc.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Naushir Patuck Nov. 22, 2023, 9:15 a.m. UTC | #1
Hi David,

Thank you for this fix.

On Wed, 22 Nov 2023 at 09:13, David Plowman via libcamera-devel
<libcamera-devel@lists.libcamera.org> wrote:
>
> The algorithm computes R/G and B/G colour ratio statistics which we
> should not allow to go to zero because there is clearly no gain you
> could apply to R or B to equalise them. Instead flag such regions as
> having "insufficient data" in the normal manner.
>
> Signed-off-by: David Plowman

Missing your email there :)

Reviewed-by: Naushir Patuck <naush@raspberrypi.com>

> ---
>  src/ipa/rpi/controller/rpi/alsc.cpp | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp b/src/ipa/rpi/controller/rpi/alsc.cpp
> index b7413611..8a205c60 100644
> --- a/src/ipa/rpi/controller/rpi/alsc.cpp
> +++ b/src/ipa/rpi/controller/rpi/alsc.cpp
> @@ -548,7 +548,9 @@ static void calculateCrCb(const RgbyRegions &awbRegion, Array2D<double> &cr,
>         for (unsigned int i = 0; i < cr.size(); i++) {
>                 auto s = awbRegion.get(i);
>
> -               if (s.counted <= minCount || s.val.gSum / s.counted <= minG) {
> +               /* Do not return unreliable, or zero, colour ratio statistics. */
> +               if (s.counted <= minCount || s.val.gSum / s.counted <= minG ||
> +                   s.val.rSum / s.counted <= minG || s.val.bSum / s.counted <= minG) {
>                         cr[i] = cb[i] = InsufficientData;
>                         continue;
>                 }
> --
> 2.30.2
>
Kieran Bingham Nov. 22, 2023, 9:23 a.m. UTC | #2
Quoting Naushir Patuck via libcamera-devel (2023-11-22 09:15:58)
> Hi David,
> 
> Thank you for this fix.
> 
> On Wed, 22 Nov 2023 at 09:13, David Plowman via libcamera-devel
> <libcamera-devel@lists.libcamera.org> wrote:
> >
> > The algorithm computes R/G and B/G colour ratio statistics which we
> > should not allow to go to zero because there is clearly no gain you
> > could apply to R or B to equalise them. Instead flag such regions as
> > having "insufficient data" in the normal manner.
> >
> > Signed-off-by: David Plowman
> 
> Missing your email there :)

Can be fixed while applying...

> 
> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>

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

> 
> > ---
> >  src/ipa/rpi/controller/rpi/alsc.cpp | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp b/src/ipa/rpi/controller/rpi/alsc.cpp
> > index b7413611..8a205c60 100644
> > --- a/src/ipa/rpi/controller/rpi/alsc.cpp
> > +++ b/src/ipa/rpi/controller/rpi/alsc.cpp
> > @@ -548,7 +548,9 @@ static void calculateCrCb(const RgbyRegions &awbRegion, Array2D<double> &cr,
> >         for (unsigned int i = 0; i < cr.size(); i++) {
> >                 auto s = awbRegion.get(i);
> >
> > -               if (s.counted <= minCount || s.val.gSum / s.counted <= minG) {
> > +               /* Do not return unreliable, or zero, colour ratio statistics. */
> > +               if (s.counted <= minCount || s.val.gSum / s.counted <= minG ||
> > +                   s.val.rSum / s.counted <= minG || s.val.bSum / s.counted <= minG) {
> >                         cr[i] = cb[i] = InsufficientData;
> >                         continue;
> >                 }
> > --
> > 2.30.2
> >
David Plowman Nov. 22, 2023, 9:24 a.m. UTC | #3
Thank you!!

David

On Wed, 22 Nov 2023 at 09:23, Kieran Bingham <
kieran.bingham@ideasonboard.com> wrote:

> Quoting Naushir Patuck via libcamera-devel (2023-11-22 09:15:58)
> > Hi David,
> >
> > Thank you for this fix.
> >
> > On Wed, 22 Nov 2023 at 09:13, David Plowman via libcamera-devel
> > <libcamera-devel@lists.libcamera.org> wrote:
> > >
> > > The algorithm computes R/G and B/G colour ratio statistics which we
> > > should not allow to go to zero because there is clearly no gain you
> > > could apply to R or B to equalise them. Instead flag such regions as
> > > having "insufficient data" in the normal manner.
> > >
> > > Signed-off-by: David Plowman
> >
> > Missing your email there :)
>
> Can be fixed while applying...
>
> >
> > Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>
> >
> > > ---
> > >  src/ipa/rpi/controller/rpi/alsc.cpp | 4 +++-
> > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp
> b/src/ipa/rpi/controller/rpi/alsc.cpp
> > > index b7413611..8a205c60 100644
> > > --- a/src/ipa/rpi/controller/rpi/alsc.cpp
> > > +++ b/src/ipa/rpi/controller/rpi/alsc.cpp
> > > @@ -548,7 +548,9 @@ static void calculateCrCb(const RgbyRegions
> &awbRegion, Array2D<double> &cr,
> > >         for (unsigned int i = 0; i < cr.size(); i++) {
> > >                 auto s = awbRegion.get(i);
> > >
> > > -               if (s.counted <= minCount || s.val.gSum / s.counted <=
> minG) {
> > > +               /* Do not return unreliable, or zero, colour ratio
> statistics. */
> > > +               if (s.counted <= minCount || s.val.gSum / s.counted <=
> minG ||
> > > +                   s.val.rSum / s.counted <= minG || s.val.bSum /
> s.counted <= minG) {
> > >                         cr[i] = cb[i] = InsufficientData;
> > >                         continue;
> > >                 }
> > > --
> > > 2.30.2
> > >
>

Patch
diff mbox series

diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp b/src/ipa/rpi/controller/rpi/alsc.cpp
index b7413611..8a205c60 100644
--- a/src/ipa/rpi/controller/rpi/alsc.cpp
+++ b/src/ipa/rpi/controller/rpi/alsc.cpp
@@ -548,7 +548,9 @@  static void calculateCrCb(const RgbyRegions &awbRegion, Array2D<double> &cr,
 	for (unsigned int i = 0; i < cr.size(); i++) {
 		auto s = awbRegion.get(i);
 
-		if (s.counted <= minCount || s.val.gSum / s.counted <= minG) {
+		/* Do not return unreliable, or zero, colour ratio statistics. */
+		if (s.counted <= minCount || s.val.gSum / s.counted <= minG ||
+		    s.val.rSum / s.counted <= minG || s.val.bSum / s.counted <= minG) {
 			cr[i] = cb[i] = InsufficientData;
 			continue;
 		}