From 7499c3b375ce88fe7fcfe675f9f4dfdc929b6c4f Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Sat, 22 May 2021 11:32:16 +0800 Subject: [PATCH] clip values can be derived from lut shape also makes it clear that indices won't be out of range --- pyqtgraph/functions_numba.py | 7 ++++--- pyqtgraph/graphicsItems/ImageItem.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyqtgraph/functions_numba.py b/pyqtgraph/functions_numba.py index a78a1015..83fdb8b1 100644 --- a/pyqtgraph/functions_numba.py +++ b/pyqtgraph/functions_numba.py @@ -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) diff --git a/pyqtgraph/graphicsItems/ImageItem.py b/pyqtgraph/graphicsItems/ImageItem.py index e01ddd14..84699748 100644 --- a/pyqtgraph/graphicsItems/ImageItem.py +++ b/pyqtgraph/graphicsItems/ImageItem.py @@ -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