Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## matplotlib-users

 [Matplotlib-users] Re verse colormapping/LUT? From: thkoe002 - 2009-10-12 16:26:48 ```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? Thanks in advance, cheers 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. ```
 Re: [Matplotlib-users] Re verse colormapping/LUT? From: thkoe002 - 2009-10-14 13:50:53 ```Ok, I'll answer my own question. I got the answer from http://groups.google.com/group/de.comp.lang.python/browse_thread/thread/5d9a315c3d3ac0f5 , 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))[0] 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): http://www.nabble.com/file/p25891118/jet.png http://www.nabble.com/file/p25891118/flag.png http://www.nabble.com/file/p25891118/prism.png cheers 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? > > Thanks in advance, cheers > > Thomas > -- View this message in context: http://www.nabble.com/Reverse-colormapping-LUT--tp25858855p25891118.html Sent from the matplotlib - users mailing list archive at Nabble.com. ```