Merge branch 'faster-make-argb' into develop
- Speed improvements in functions.makeARGB - ImageItem is faster by avoiding makeQImage(transpose=True)
This commit is contained in:
commit
c1f72b29c6
@ -782,25 +782,6 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
|||||||
if levels is not None and not isinstance(levels, np.ndarray):
|
if levels is not None and not isinstance(levels, np.ndarray):
|
||||||
levels = np.array(levels)
|
levels = np.array(levels)
|
||||||
|
|
||||||
## sanity checks
|
|
||||||
#if data.ndim == 3:
|
|
||||||
#if data.shape[2] not in (3,4):
|
|
||||||
#raise Exception("data.shape[2] must be 3 or 4")
|
|
||||||
##if lut is not None:
|
|
||||||
##raise Exception("can not use lookup table with 3D data")
|
|
||||||
#elif data.ndim != 2:
|
|
||||||
#raise Exception("data must be 2D or 3D")
|
|
||||||
|
|
||||||
#if lut is not None:
|
|
||||||
##if lut.ndim == 2:
|
|
||||||
##if lut.shape[1] :
|
|
||||||
##raise Exception("lut.shape[1] must be 3 or 4")
|
|
||||||
##elif lut.ndim != 1:
|
|
||||||
##raise Exception("lut must be 1D or 2D")
|
|
||||||
#if lut.dtype != np.ubyte:
|
|
||||||
#raise Exception('lookup table must have dtype=ubyte (got %s instead)' % str(lut.dtype))
|
|
||||||
|
|
||||||
|
|
||||||
if levels is not None:
|
if levels is not None:
|
||||||
if levels.ndim == 1:
|
if levels.ndim == 1:
|
||||||
if len(levels) != 2:
|
if len(levels) != 2:
|
||||||
@ -813,16 +794,6 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
|||||||
else:
|
else:
|
||||||
print(levels)
|
print(levels)
|
||||||
raise Exception("levels argument must be 1D or 2D.")
|
raise Exception("levels argument must be 1D or 2D.")
|
||||||
#levels = np.array(levels)
|
|
||||||
#if levels.shape == (2,):
|
|
||||||
#pass
|
|
||||||
#elif levels.shape in [(3,2), (4,2)]:
|
|
||||||
#if data.ndim == 3:
|
|
||||||
#raise Exception("Can not use 2D levels with 3D data.")
|
|
||||||
#if lut is not None:
|
|
||||||
#raise Exception('Can not use 2D levels and lookup table together.')
|
|
||||||
#else:
|
|
||||||
#raise Exception("Levels must have shape (2,) or (3,2) or (4,2)")
|
|
||||||
|
|
||||||
prof.mark('1')
|
prof.mark('1')
|
||||||
|
|
||||||
@ -865,8 +836,6 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
|||||||
|
|
||||||
## copy data into ARGB ordered array
|
## copy data into ARGB ordered array
|
||||||
imgData = np.empty(data.shape[:2]+(4,), dtype=np.ubyte)
|
imgData = np.empty(data.shape[:2]+(4,), dtype=np.ubyte)
|
||||||
if data.ndim == 2:
|
|
||||||
data = data[..., np.newaxis]
|
|
||||||
|
|
||||||
prof.mark('4')
|
prof.mark('4')
|
||||||
|
|
||||||
@ -875,20 +844,26 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
|||||||
else:
|
else:
|
||||||
order = [2,1,0,3] ## for some reason, the colors line up as BGR in the final image.
|
order = [2,1,0,3] ## for some reason, the colors line up as BGR in the final image.
|
||||||
|
|
||||||
if data.shape[2] == 1:
|
if data.ndim == 2:
|
||||||
|
# This is tempting:
|
||||||
|
# imgData[..., :3] = data[..., np.newaxis]
|
||||||
|
# ..but it turns out this is faster:
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
imgData[..., order[i]] = data[..., 0]
|
imgData[..., i] = data
|
||||||
|
elif data.shape[2] == 1:
|
||||||
|
for i in range(3):
|
||||||
|
imgData[..., i] = data[..., 0]
|
||||||
else:
|
else:
|
||||||
for i in range(0, data.shape[2]):
|
for i in range(0, data.shape[2]):
|
||||||
imgData[..., order[i]] = data[..., i]
|
imgData[..., i] = data[..., order[i]]
|
||||||
|
|
||||||
prof.mark('5')
|
prof.mark('5')
|
||||||
|
|
||||||
if data.shape[2] == 4:
|
if data.ndim == 2 or data.shape[2] == 3:
|
||||||
alpha = True
|
|
||||||
else:
|
|
||||||
alpha = False
|
alpha = False
|
||||||
imgData[..., 3] = 255
|
imgData[..., 3] = 255
|
||||||
|
else:
|
||||||
|
alpha = True
|
||||||
|
|
||||||
prof.mark('6')
|
prof.mark('6')
|
||||||
|
|
||||||
|
@ -260,8 +260,8 @@ class ImageItem(GraphicsObject):
|
|||||||
#print lut.shape
|
#print lut.shape
|
||||||
#print self.lut
|
#print self.lut
|
||||||
|
|
||||||
argb, alpha = fn.makeARGB(self.image, lut=lut, levels=self.levels)
|
argb, alpha = fn.makeARGB(self.image.transpose((1, 0, 2)[:self.image.ndim]), lut=lut, levels=self.levels)
|
||||||
self.qimage = fn.makeQImage(argb, alpha)
|
self.qimage = fn.makeQImage(argb, alpha, transpose=False)
|
||||||
prof.finish()
|
prof.finish()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user