From 2a80205dd4801cbe100dab383d30b76793699257 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sat, 30 Jan 2016 09:52:37 -0800 Subject: [PATCH] ImageItem bugfix --- pyqtgraph/graphicsItems/ImageItem.py | 8 ++++---- pyqtgraph/tests/test_functions.py | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pyqtgraph/graphicsItems/ImageItem.py b/pyqtgraph/graphicsItems/ImageItem.py index f42e78a6..f6597a9b 100644 --- a/pyqtgraph/graphicsItems/ImageItem.py +++ b/pyqtgraph/graphicsItems/ImageItem.py @@ -309,11 +309,12 @@ class ImageItem(GraphicsObject): # if the image data is a small int, then we can combine levels + lut # into a single lut for better performance - if self.levels is not None and self.levels.ndim == 1 and image.dtype in (np.ubyte, np.uint16): + levels = self.levels + if levels is not None and levels.ndim == 1 and image.dtype in (np.ubyte, np.uint16): if self._effectiveLut is None: eflsize = 2**(image.itemsize*8) ind = np.arange(eflsize) - minlev, maxlev = self.levels + minlev, maxlev = levels if lut is None: efflut = fn.rescaleData(ind, scale=255./(maxlev-minlev), offset=minlev, dtype=np.ubyte) @@ -327,8 +328,7 @@ class ImageItem(GraphicsObject): lut = self._effectiveLut levels = None - - argb, alpha = fn.makeARGB(image.transpose((1, 0, 2)[:image.ndim]), lut=lut, levels=self.levels) + argb, alpha = fn.makeARGB(image.transpose((1, 0, 2)[:image.ndim]), lut=lut, levels=levels) self.qimage = fn.makeQImage(argb, alpha, transpose=False) def paint(self, p, *args): diff --git a/pyqtgraph/tests/test_functions.py b/pyqtgraph/tests/test_functions.py index 6852bb2a..bfa7e0ea 100644 --- a/pyqtgraph/tests/test_functions.py +++ b/pyqtgraph/tests/test_functions.py @@ -249,6 +249,14 @@ def test_makeARGB(): lut = (np.arange(512, 2**16)[::-1] // 256).astype('ubyte') im2, alpha = pg.makeARGB(im1, lut=lut, levels=(512, 2**16-256)) checkImage(im2, np.clip(np.linspace(257, 2, 256), 0, 255).astype('ubyte'), alpha, False) + + lut = np.zeros(2**16, dtype='ubyte') + lut[1000:1256] = np.arange(256) + lut[1256:] = 255 + im1 = np.arange(1000, 1256).astype('uint16')[:, None] + im2, alpha = pg.makeARGB(im1, lut=lut) + checkImage(im2, np.arange(256).astype('ubyte'), alpha, False) + # float data tests