libtuning: lsc: Prevent negative values
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> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
This commit is contained in:
parent
e91f6c384f
commit
d5db46232e
1 changed files with 4 additions and 1 deletions
|
@ -59,7 +59,10 @@ class LSC(Module):
|
||||||
def _lsc_single_channel(self, channel: np.array,
|
def _lsc_single_channel(self, channel: np.array,
|
||||||
image: lt.Image, green_grid: np.array = None):
|
image: lt.Image, green_grid: np.array = None):
|
||||||
grid = self._get_grid(channel, image.w, image.h)
|
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:
|
if green_grid is None:
|
||||||
table = np.reshape(1 / grid, self.sector_shape[::-1])
|
table = np.reshape(1 / grid, self.sector_shape[::-1])
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue