makeRGBA/ImageItem: Applying alpha mask on numpy.nan data values (#406)
* Applying alpha mask on numpy.nan data values * Typesafe, checking for `data.dtype.kind`
This commit is contained in:
parent
96a4270a30
commit
071e429535
@ -1035,7 +1035,6 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||
============== ==================================================================================
|
||||
"""
|
||||
profile = debug.Profiler()
|
||||
|
||||
if data.ndim not in (2, 3):
|
||||
raise TypeError("data must be 2D or 3D")
|
||||
if data.ndim == 3 and data.shape[2] > 4:
|
||||
@ -1084,6 +1083,11 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||
else:
|
||||
dtype = np.min_scalar_type(lut.shape[0]-1)
|
||||
|
||||
# awkward, but fastest numpy native nan evaluation
|
||||
#
|
||||
nanMask = None
|
||||
if data.dtype.kind == 'f' and np.isnan(data.min()):
|
||||
nanMask = np.isnan(data)
|
||||
# Apply levels if given
|
||||
if levels is not None:
|
||||
if isinstance(levels, np.ndarray) and levels.ndim == 2:
|
||||
@ -1107,9 +1111,7 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||
maxVal = np.nextafter(maxVal, 2*maxVal)
|
||||
data = rescaleData(data, scale/(maxVal-minVal), minVal, dtype=dtype)
|
||||
|
||||
|
||||
profile()
|
||||
|
||||
# apply LUT if given
|
||||
if lut is not None:
|
||||
data = applyLookupTable(data, lut)
|
||||
@ -1153,6 +1155,11 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||
else:
|
||||
alpha = True
|
||||
|
||||
# apply nan mask through alpha channel
|
||||
if nanMask is not None:
|
||||
alpha = True
|
||||
imgData[nanMask, 3] = 0
|
||||
|
||||
profile()
|
||||
return imgData, alpha
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user