Jet colormap to grayscale

1,429 views
Skip to first unread message

Guillaume CALMETTES

unread,
Nov 22, 2012, 11:08:01 PM11/22/12
to scikit...@googlegroups.com
Hello,

I am looking to convert an image saved with the jet colormap to grayscale.
I tried to play a bit with the color module of skimage, but for the moment I couldn't manage to to map the jet colormap to linearly go from dark to light shades of gray. The main problem when applying a basic rgb2gray conversion is that the min/max values (blue and red) converge to the same dark value in the grayscale image, while the mid-range values (yellow/green) become the brightest.

Do someone has any trick to convert a "jet image" to grayscale?

Thanks a lot

Guillaume

PS: I have attached a picture as an example if you're willing to play with it ;)


im2.tif
cmap.png

Schönberger Johannes

unread,
Nov 23, 2012, 12:39:37 PM11/23/12
to scikit...@googlegroups.com
Hi,

this might be a way to achieve this:

1. create jet colormap
2. convert color map to HSV-space and sort according to hue
3. use sorted jet color map as lookup table / colormap for image

I hope this helps.

Johannes Schönberger
> --
>
>
> <im2.tif><cmap.png>

Guillaume CALMETTES

unread,
Nov 23, 2012, 12:48:14 PM11/23/12
to scikit...@googlegroups.com
Hi Johannes,

Thanks, I'll try!

Guillaume
> --
>
>

Stéfan van der Walt

unread,
Nov 25, 2012, 11:25:36 PM11/25/12
to scikit...@googlegroups.com
Hi Guillaume

On Thu, Nov 22, 2012 at 8:08 PM, Guillaume CALMETTES
<guillaume...@gmail.com> wrote:
> Do someone has any trick to convert a "jet image" to grayscale?

Here's a snippet that does it by brute force lookup:

https://gist.github.com/4146612

Hope that helps!
Stéfan

Guillaume CALMETTES

unread,
Nov 25, 2012, 11:37:54 PM11/25/12
to scikit...@googlegroups.com
Hi Stefan,

Works perfectly.

However, I'm not sure why but I had to initialize the jet colormap object to create the _lut array.

I replaced:
lut = plt.cm.jet._lut[..., :3]

By:
jet = plt.cm.jet
jet._init()
lut = jet._lut[..., :3]

Thanks a lot.

Guillaume
> --
>
>

Reply all
Reply to author
Forward
0 new messages