[v2,22/25] libtuning: lsc: Prevent negative values
diff mbox series

Message ID 20240628104828.2928109-23-stefan.klug@ideasonboard.com
State Superseded
Headers show
Series
  • Add ccm calibration to libtuning
Related show

Commit Message

Stefan Klug June 28, 2024, 10:47 a.m. UTC
In cases where the calibration image contains super dark areas, or when
an invalid blacklevel was supplied, the grid might get close to zero or
negative. This would have bad effects on the 1/grid later. So clamp the
values to a small positive number.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 utils/tuning/libtuning/modules/lsc/lsc.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart June 29, 2024, 12:25 a.m. UTC | #1
Hi Stefan,

Thank you for the patch.

On Fri, Jun 28, 2024 at 12:47:15PM +0200, Stefan Klug wrote:
> In cases where the calibration image contains super dark areas, or when
> an invalid blacklevel was supplied, the grid might get close to zero or
> negative. This would have bad effects on the 1/grid later. So clamp the
> values to a small positive number.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> ---
>  utils/tuning/libtuning/modules/lsc/lsc.py | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/utils/tuning/libtuning/modules/lsc/lsc.py b/utils/tuning/libtuning/modules/lsc/lsc.py
> index 344a07a3d443..b6a24cf42874 100644
> --- a/utils/tuning/libtuning/modules/lsc/lsc.py
> +++ b/utils/tuning/libtuning/modules/lsc/lsc.py
> @@ -59,7 +59,8 @@ class LSC(Module):
>      def _lsc_single_channel(self, channel: np.array,
>                              image: lt.Image, green_grid: np.array = None):
>          grid = self._get_grid(channel, image.w, image.h)
> -        grid -= image.blacklevel_16
> +        grid = np.maximum(grid - image.blacklevel_16, 0.1)

I think a comment would be useful.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Should we detect during tuning if an image is too dark, and report a
warning or error out ?

> +
>          if green_grid is None:
>              table = np.reshape(1 / grid, self.sector_shape[::-1])
>          else:

Patch
diff mbox series

diff --git a/utils/tuning/libtuning/modules/lsc/lsc.py b/utils/tuning/libtuning/modules/lsc/lsc.py
index 344a07a3d443..b6a24cf42874 100644
--- a/utils/tuning/libtuning/modules/lsc/lsc.py
+++ b/utils/tuning/libtuning/modules/lsc/lsc.py
@@ -59,7 +59,8 @@  class LSC(Module):
     def _lsc_single_channel(self, channel: np.array,
                             image: lt.Image, green_grid: np.array = None):
         grid = self._get_grid(channel, image.w, image.h)
-        grid -= image.blacklevel_16
+        grid = np.maximum(grid - image.blacklevel_16, 0.1)
+
         if green_grid is None:
             table = np.reshape(1 / grid, self.sector_shape[::-1])
         else: