Pseudocolor implementation with OpenCV.
In Computer Vision works in a lot of cases with gray images because there are a lot of motives. But human vision don’t perceives the gray levels so well as color levels.
Then if we need show a image to a person, we can color it. But, how is the best way to coloring gray image?
There are 3 ways to do it: Manually, automatically and colored by ranges.
In this tutorial, i go to develop the way most common automatic for gray image coloring.
To do it we need know we go to receive a gray level and we need return 3 values, one for red, one for blue and other for green.
We go to use this function:
And r(x,y) is the gray level and p is the number of repetitions and is the displacement.
Then we only need define the p and for each channel.
If we create a plot with this function with this parameters for red, green and blue ((2,0),(2,-0.1),(2,-0.3)) we get:
Then we only need set the gray level in range 0 to 1 and the sine returns values from 0 to 1 we interpret as float image values or we set in range 0 to 255.
To finish this is the result:
8 Comments + Add Comment
Got anything to say? Go ahead and leave a comment!
Category
- blenderocv (1)
- Personal (2)
- Tutorials (24)
- ActionScript (1)
- Blender (2)
- CSS (1)
- Java and Netbeans (1)
- Linux/Unix (7)
- OpenCV (15)
- OpenGL (1)
- other (4)
- Uncategorized (2)
- Works (2)
Last comments
Tag cloud
Twitter: damiles3D
- Finishing coding a card marker AR functions in API. Next step, facedetection.
- Que tardecita. Después de correr 5km para recoger el coche acabo haciendo un duatlon cogiendo bici para volver en tren. X(
- En el tren de camino al trabajo. Lunes lunero....
- @Neoxisme do you want this list of camera features to set http://t.co/jCqNnWct
- Finished QR integration, and first basic UI OpenGL framework.
- Review Finished, I like this chapter. Now continue developing OpenGL user interfaces and Events management
- Reviwing a book... only review 30 pages and 15 gnuplot scripts.
- @pipotux Siempre que puedas evitar pagar la licencia ;)
- @pipotux Suena dificil! :S
- @joshis_tweets Check this first. Read it http://t.co/3AEMSxRa




Posted under: 

Hi! First of all, nice blog
I am facing the opposite problem. I’ve a pseudocolor image that represents reflectivity (or energy). From black / blue values (no reflectivity) to red / white values (maximum reflectivity). In fact, my images are exactly the inverse of what you are showing: blue regions come from dark values, red regions come from white values.
I guess I could use something like your function to map that 3 channel image back to a gray level image (because I’m using OpenCV to analyze it, and thus color is not so important). Right now, I’m simply weighting each channel:
graylevel = 0.6 * r + 0.4 * g + 0.2 * b
That way, white/red regions become brighter than blue/black regions.
But I don’t really like that solution. Then I thought I could create a LUT table… but it would be much better with a map function like yours. Any experience with something like that?
Hi Luis, you know the color space and algorithm was encoding this image?. If you know or can determine it, then you can create a reverse function. It’s only i can help. It’s good you create lut table for better performance.
Regards David.
It’s plain RGB, but no idea about the algorithm. The scale is similar to this one: http://www.efg2.com/Lab/Library/Color/AccuweatherRadarReflectivity.jpg
So yes, I think I’ll prepare a LUT table and that’s all
The image is plain rgb, but you can use other color space to work, for example Lab space or HSV or similar because have some properties than others.
The scale is simiar to this? http://en.wikipedia.org/wiki/Color_theory#Warm_vs._cool_colors
Well, something similar. Indeed, the scale is just the same that Hue values take in HSV, more like this:
http://en.wikipedia.org/wiki/File:HSV-RGB-comparison.svg
In fact, I also wanted to try those fuzzy logic sets to go from color to HUE. That would work too, I guess. There’s no violet (no colors above 240º), so I would have no problem with circling colors…
Ok, just in case you need it, I think I have something useful here. I tried with LUTs, but finding the right bin is not trivial (color distances, you know). So I went back to HSV.
The thing is, in HSV, that lower and higher V values produce undefined H values. Therefore, H is not enough to map from pseudocolor to gray.
But you get a nice mapping if the gray value is given by the following expression:
gray = (240.0 – HUE) * (240.0 – HUE) * V.
Then you adjust the dynamic range back to 0-255.
That way, low light values produce low gray values, high light values produce high gray values and middle tones are handled by HUE.
That’s of course if the pseudocolor map is similar to what we talked before: white-red (0 HUE)-yellow-green-cyan-blue (240 HUE)-black
Hello,
What is the of the mapping function?
Do you have any references for it?
Hi Olu, the mapping function is the above funcion on tutorial. In code i generat under pseudocolor.c a table with this function for all value colors 0..255 and i map the image with pseudocolor function.