ndarray indexing is faster than np.take
This commit is contained in:
parent
29ad432f5a
commit
f59097a484
@ -455,14 +455,24 @@ class ImageItem(GraphicsObject):
|
|||||||
lut = self._effectiveLut
|
lut = self._effectiveLut
|
||||||
levels = None
|
levels = None
|
||||||
|
|
||||||
if image.dtype == self._xp.uint16 or (image.ndim == 3 and image.shape[2] == 3):
|
|
||||||
# apply the effective lut early for the following types:
|
# apply the effective lut early for the following types:
|
||||||
|
if image.dtype == self._xp.uint16 and (image.ndim == 2 or image.shape[2] == 1):
|
||||||
# 1) uint16 mono
|
# 1) uint16 mono
|
||||||
|
if lut.ndim == 2:
|
||||||
|
if lut.shape[1] == 3: # rgb
|
||||||
|
# convert rgb lut to rgba so that it is 32-bits
|
||||||
|
lut = numpy.column_stack([lut, numpy.full(lut.shape[0], 255, dtype=numpy.uint8)])
|
||||||
|
if lut.shape[1] == 4: # rgba
|
||||||
|
lut = lut.view(numpy.uint32)
|
||||||
|
image = lut.ravel()[image]
|
||||||
|
lut = None
|
||||||
|
# now both levels and lut are None
|
||||||
|
if image.dtype == numpy.uint32:
|
||||||
|
image = image.view(numpy.uint8).reshape(image.shape + (4,))
|
||||||
|
elif image.ndim == 3 and image.shape[2] == 3:
|
||||||
# 2) {uint8, uint16} rgb
|
# 2) {uint8, uint16} rgb
|
||||||
# this converts the input image to an uint8 image of shape
|
# for rgb images, the lut will be 1d
|
||||||
# (h, w) or (h, w, 3) or (h, w, 4), depending on the lut's shape.
|
image = lut.ravel()[image]
|
||||||
# we don't do it for uint8 mono so that it will use Format_Indexed8
|
|
||||||
image = fn.applyLookupTable(image, lut)
|
|
||||||
lut = None
|
lut = None
|
||||||
# now both levels and lut are None
|
# now both levels and lut are None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user