 # Re verse colormapping/LUT?

Hi,

following problem: Let's say I have a couple of .png images that were
produced with imshow() and the jet() (==default) colormap. The original data
was 8 bit intensity data, now the images are 24 bit with false colors /
pseudocolors.
Now, is there a (simple?) way to calculate back from those 24 bit images to
the 8 bit intensity information? Of course this can only work with bijective
colormaps and if the colormap is well known; both is the case here.

Any ideas?

Thomas

···

View this message in context: http://www.nabble.com/Reverse-colormapping-LUT--tp25858855p25858855.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

, already 2 months old, but I wasn't aware. Code snippet below.

···

----------------
import Image
from pylab import *

#generate intensity map
a=meshgrid(arange(256),arange(256))

f=figure()
for map in [eval("cm."+t) for t in dir(cm) if "N" in dir(eval("cm."+t))]:
#generate false color map
color_image=(map(a)*255.).astype(uint8)

#rasterize colormap
gray_to_color=(map(linspace(0,1,256))[:,:3]*255).astype(uint8)

#create reverse LUT
color_to_gray = zeros((256, 256, 256), dtype=uint8)
color_to_gray [gray_to_color[:,0], gray_to_color[:,1],
gray_to_color[:,2]] = arange (0, 256, dtype=uint8)

# use reverse LUT
new_gray_image = color_to_gray[color_image[:,:,0], color_image[:,:,1],
color_image[:,:,2]]

gray()
subplot(131)
imshow(a)
title("intensity")
subplot(132)
imshow(color_image)
title("intensity->%s"%map.name)
subplot(133)
imshow(new_gray_image)
title("intensity->%s->intensity"%map.name)
f.savefig("c:/temp/%s.png"%map.name)
-----------------

By the way, the resulting plots show that all the colormaps except cm.prism
are bijective (even for example mc.flag):

Thomas

thkoe002 wrote:

Hi,

following problem: Let's say I have a couple of .png images that were
produced with imshow() and the jet() (==default) colormap. The original
data was 8 bit intensity data, now the images are 24 bit with false colors
/ pseudocolors.
Now, is there a (simple?) way to calculate back from those 24 bit images
to the 8 bit intensity information? Of course this can only work with
bijective colormaps and if the colormap is well known; both is the case
here.

Any ideas?