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:
parent
03ddf92839
commit
7499c3b375
@ -22,18 +22,19 @@ def rescaleData(data, scale, offset, dtype, clip):
|
|||||||
return data_out
|
return data_out
|
||||||
|
|
||||||
@numba.jit(nopython=True)
|
@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 r in range(xx.shape[0]):
|
||||||
for c in range(xx.shape[1]):
|
for c in range(xx.shape[1]):
|
||||||
val = (xx[r, c] - offset) * scale
|
val = (xx[r, c] - offset) * scale
|
||||||
val = min(max(val, vmin), vmax)
|
val = min(max(val, vmin), vmax)
|
||||||
yy[r, c] = lut[int(val)]
|
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
|
# data should be floating point and 2d
|
||||||
# lut is 1d
|
# lut is 1d
|
||||||
data_out = np.empty_like(data, dtype=lut.dtype)
|
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
|
return data_out
|
||||||
|
|
||||||
@numba.jit(nopython=True)
|
@numba.jit(nopython=True)
|
||||||
|
@ -516,7 +516,7 @@ class ImageItem(GraphicsObject):
|
|||||||
fn_numba = fn.getNumbaFunctions()
|
fn_numba = fn.getNumbaFunctions()
|
||||||
if xp == numpy and image.flags.c_contiguous and dtype == xp.uint16 and fn_numba is not None:
|
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)
|
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:
|
if image.dtype == xp.uint32:
|
||||||
image = image[..., xp.newaxis].view(xp.uint8)
|
image = image[..., xp.newaxis].view(xp.uint8)
|
||||||
return image, None, None, augmented_alpha
|
return image, None, None, augmented_alpha
|
||||||
|
Loading…
Reference in New Issue
Block a user