[PATCH v3 22/23] libtuning: lsc: Prevent negative values

Paul Elder paul.elder at ideasonboard.com
Fri Jul 5 08:44:49 CEST 2024


On Wed, Jul 03, 2024 at 04:17:11PM +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 at ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder at ideasonboard.com>

> ---
>  utils/tuning/libtuning/modules/lsc/lsc.py | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/utils/tuning/libtuning/modules/lsc/lsc.py b/utils/tuning/libtuning/modules/lsc/lsc.py
> index 344a07a3d443..e0ca22ebe9bd 100644
> --- a/utils/tuning/libtuning/modules/lsc/lsc.py
> +++ b/utils/tuning/libtuning/modules/lsc/lsc.py
> @@ -59,7 +59,10 @@ 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
> +        # Clamp the values to a small positive, so that the following 1/grid
> +        # doesn't produce negative results.
> +        grid = np.maximum(grid - image.blacklevel_16, 0.1)
> +
>          if green_grid is None:
>              table = np.reshape(1 / grid, self.sector_shape[::-1])
>          else:
> -- 
> 2.43.0
> 


More information about the libcamera-devel mailing list