clip values can be derived from lut shape

also makes it clear that indices won't be out of range
This commit is contained in:
KIU Shueng Chuan 2021-05-22 11:32:16 +08:00
parent 03ddf92839
commit 7499c3b375
2 changed files with 5 additions and 4 deletions

View File

@ -22,18 +22,19 @@ def rescaleData(data, scale, offset, dtype, clip):
return data_out
@numba.jit(nopython=True)
def rescale_and_lookup1d_function(xx, scale, offset, vmin, vmax, lut, yy):
def rescale_and_lookup1d_function(xx, scale, offset, lut, yy):
vmin, vmax = 0, lut.shape[0] - 1
for r in range(xx.shape[0]):
for c in range(xx.shape[1]):
val = (xx[r, c] - offset) * scale
val = min(max(val, vmin), vmax)
yy[r, c] = lut[int(val)]
def rescale_and_lookup1d(data, scale, offset, clip, lut):
def rescale_and_lookup1d(data, scale, offset, lut):
# data should be floating point and 2d
# lut is 1d
data_out = np.empty_like(data, dtype=lut.dtype)
rescale_and_lookup1d_function(data, float(scale), float(offset), float(clip[0]), float(clip[1]), lut, data_out)
rescale_and_lookup1d_function(data, float(scale), float(offset), lut, data_out)
return data_out
@numba.jit(nopython=True)

View File

@ -516,7 +516,7 @@ class ImageItem(GraphicsObject):
fn_numba = fn.getNumbaFunctions()
if xp == numpy and image.flags.c_contiguous and dtype == xp.uint16 and fn_numba is not None:
lut, augmented_alpha = self._convert_2dlut_to_1dlut(lut)
image = fn_numba.rescale_and_lookup1d(image, scale/rng, minVal, (0, num_colors-1), lut)
image = fn_numba.rescale_and_lookup1d(image, scale/rng, minVal, lut)
if image.dtype == xp.uint32:
image = image[..., xp.newaxis].view(xp.uint8)
return image, None, None, augmented_alpha