def GetLUTValue(self, data, window, level): """Apply the RGB Look-Up Table for the data and window/level value. Parameters ---------- data : numpy array Pixel data array from pydicom dataset window : float Image window value level : float Image window level or width Returns ------- numpy array Modified numpy array with RGB LUT applied """ lutvalue = util.piecewise(data, [ data <= (level - 0.5 - (window - 1) / 2), data > (level - 0.5 + (window - 1) / 2) ], [ 0, 255, lambda data: ((data - (level - 0.5)) / (window - 1) + 0.5) * (255 - 0) ]) # Convert the resultant array to an unsigned 8-bit array to create # an 8-bit grayscale LUT since the range is only from 0 to 255 return np.array(lutvalue, dtype=np.uint8)
def GetLUTValue(self, data, window, level): """Apply the RGB Look-Up Table for the data and window/level value.""" lutvalue = util.piecewise(data, [data <= (level - 0.5 - (window - 1) / 2), data > (level - 0.5 + (window - 1) / 2)], [0, 255, lambda data: ((data - (level - 0.5)) / (window-1) + 0.5) * (255 - 0)]) # Convert the resultant array to an unsigned 8-bit array to create # an 8-bit grayscale LUT since the range is only from 0 to 255 return np.array(lutvalue, dtype=np.uint8)