I have a given image img (16 bits gray-level image whose values range from 0 to 65535) and a colormap colormap_file which is a 8 bits RGB 256*256 pixels image.
Thus, thanks to such a colormap I am able, for all pixels in the valueImage, to assign a (R, G, B) triplet.
Currently, it is done in pure Python through this function:
def transcodeThroughColormap(img, colormap_file):
colormap = np.array(Image.open(colormap_file))
flat_colormap = colormap.flatten()
idx = img
i = np.floor(idx / 256)
j = idx - (i * 256)
R = flat_colormap[(3 * (i * 256 + j)).astype('int')]
G = flat_colormap[(3 * (i * 256 + j) + 1).astype('int')]
B = flat_colormap[(3 * (i * 256 + j) + 2).astype('int')]
rgbArray = np.zeros(shape=(img.shape[0], img.shape[1], 3))
rgbArray[..., 0] = R
rgbArray[..., 1] = G
rgbArray[..., 2] = B
return rgbArray
However, I would like to apply such a colormap but in my fragment shader.
Thus, I wonder I will have to use two sampler2D in my fragment shader but I do not how to achieve the same result as in Python.