UPDATE NOTICE This project is now included in libfacerec
It's a fact, that human perception isn't built for observing fine changes in grayscale images. Human sensors (eyes and stuff) are more sensitive to observing changes between colors, so you often need to recolor your grayscale images to get a clue about them. Yesterday I needed to visualize some data in OpenCV. It's easy to apply a colormap in MATLAB, but OpenCV doesn't come with predefined colormaps. I don't have much knowledge about colormaps and I am totally off when it comes to choosing colors anyway (my former art teacher will acknowledge), but there are people with a lot more experience. One page I've found is the blog of Matteo Niccoli, who shares some colormaps on his FEX page, along with interesting links to latest research.
So I simply took his colormaps (Thanks!), some GNU Octave colormaps and wrapped them into classes. The source code is now on my github account:
Using a colormap is then as easy as writing:
#include <cv.h> #include "colormap.hpp" using namespace cv; int main(int argc, const char *argv[]) { Mat img = imread("image.jpg",0); colormap::Jet jet; // default: 256-levels Mat colored = jet(img); //... }
Here are the colormaps included in the code. You can have a look into the main.cpp to see how I've created the color scales below:
Please note, that the ColorMap class returns a CV_32FC3 matrix (float values from (0.0,…,1.0)). In order to display an image you have to convert the scale:
// ... Mat colored = jet(img); colored.convertTo(colored, CV_8UC3, 255.0);
I hope this saves someone some time. I've put my code under a BSD License, so feel free to use it and enhance it with your own colormaps!
Discussion
Thank you for sharing my colormaps. Great work!
Thanks for allowing me to use them!
Great work guys!
Just one thing… Im getting an assertion fail in the interp1_ function.
Hi Rodrigo. It's fixed.
Thanks a lot for sharing this!
Just wanted to point out that on OpenCV 2.2, using normalize on anything other than a 1 channel matrix will produce an assertion error inside minMaxLoc. Not sure if you want to add an OpenCV version requirement to 2.3 inside CMake.
I've completely kicked normalize. It's not needed in the ColorMap class and it's sufficient to convert the scale (convertTo) for displaying the image.