OpenCV  4.1.1-pre
Open Source Computer Vision
Looking for a C++ dev who knows OpenCV?
I'm looking for work. Hire me!
ColorMaps in OpenCV

The human perception isn't built for observing fine changes in grayscale images. More...

Collaboration diagram for ColorMaps in OpenCV:

Enumerations

enum  cv::ColormapTypes {
  cv::COLORMAP_AUTUMN = 0,
  cv::COLORMAP_BONE = 1,
  cv::COLORMAP_JET = 2,
  cv::COLORMAP_WINTER = 3,
  cv::COLORMAP_RAINBOW = 4,
  cv::COLORMAP_OCEAN = 5,
  cv::COLORMAP_SUMMER = 6,
  cv::COLORMAP_SPRING = 7,
  cv::COLORMAP_COOL = 8,
  cv::COLORMAP_HSV = 9,
  cv::COLORMAP_PINK = 10,
  cv::COLORMAP_HOT = 11,
  cv::COLORMAP_PARULA = 12,
  cv::COLORMAP_MAGMA = 13,
  cv::COLORMAP_INFERNO = 14,
  cv::COLORMAP_PLASMA = 15,
  cv::COLORMAP_VIRIDIS = 16,
  cv::COLORMAP_CIVIDIS = 17,
  cv::COLORMAP_TWILIGHT = 18,
  cv::COLORMAP_TWILIGHT_SHIFTED = 19
}
 GNU Octave/MATLAB equivalent colormaps. More...
 

Functions

void cv::applyColorMap (InputArray src, OutputArray dst, int colormap)
 Applies a GNU Octave/MATLAB equivalent colormap on a given image. More...
 
void cv::applyColorMap (InputArray src, OutputArray dst, InputArray userColor)
 Applies a user colormap on a given image. More...
 

Detailed Description

The human perception isn't built for observing fine changes in grayscale images.

Human eyes are more sensitive to observing changes between colors, so you often need to recolor your grayscale images to get a clue about them. OpenCV now comes with various colormaps to enhance the visualization in your computer vision application.

In OpenCV you only need applyColorMap to apply a colormap on a given image. The following sample code reads the path to an image from command line, applies a Jet colormap on it and shows the result:

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
#include <iostream>
using namespace std;
int main(int argc, const char *argv[])
{
// We need an input image. (can be grayscale or color)
if (argc < 2)
{
cerr << "We need an image to process here. Please run: colorMap [path_to_image]" << endl;
return -1;
}
Mat img_in = imread(argv[1]);
if(img_in.empty())
{
cerr << "Sample image (" << argv[1] << ") is empty. Please adjust your path, so it points to a valid input image!" << endl;
return -1;
}
// Holds the colormap version of the image:
Mat img_color;
// Apply the colormap:
applyColorMap(img_in, img_color, COLORMAP_JET);
// Show the result:
imshow("colorMap", img_color);
waitKey(0);
return 0;
}
See also
ColormapTypes

Enumeration Type Documentation

◆ ColormapTypes

#include <opencv2/imgproc.hpp>

GNU Octave/MATLAB equivalent colormaps.

Enumerator
COLORMAP_AUTUMN 
colorscale_autumn.jpg
autumn
COLORMAP_BONE 
colorscale_bone.jpg
bone
COLORMAP_JET 
colorscale_jet.jpg
jet
COLORMAP_WINTER 
colorscale_winter.jpg
winter
COLORMAP_RAINBOW 
colorscale_rainbow.jpg
rainbow
COLORMAP_OCEAN 
colorscale_ocean.jpg
ocean
COLORMAP_SUMMER 
colorscale_summer.jpg
summer
COLORMAP_SPRING 
colorscale_spring.jpg
spring
COLORMAP_COOL 
colorscale_cool.jpg
cool
COLORMAP_HSV 
colorscale_hsv.jpg
HSV
COLORMAP_PINK 
colorscale_pink.jpg
pink
COLORMAP_HOT 
colorscale_hot.jpg
hot
COLORMAP_PARULA 
colorscale_parula.jpg
parula
COLORMAP_MAGMA 
colorscale_magma.jpg
magma
COLORMAP_INFERNO 
colorscale_inferno.jpg
inferno
COLORMAP_PLASMA 
colorscale_plasma.jpg
plasma
COLORMAP_VIRIDIS 
colorscale_viridis.jpg
viridis
COLORMAP_CIVIDIS 
colorscale_cividis.jpg
cividis
COLORMAP_TWILIGHT 
colorscale_twilight.jpg
twilight
COLORMAP_TWILIGHT_SHIFTED 
colorscale_twilight_shifted.jpg
twilight shifted

Function Documentation

◆ applyColorMap() [1/2]

void cv::applyColorMap ( InputArray  src,
OutputArray  dst,
int  colormap 
)

#include <opencv2/imgproc.hpp>

Applies a GNU Octave/MATLAB equivalent colormap on a given image.

Parameters
srcThe source image, grayscale or colored of type CV_8UC1 or CV_8UC3.
dstThe result is the colormapped source image. Note: Mat::create is called on dst.
colormapThe colormap to apply, see ColormapTypes
Examples:
samples/cpp/falsecolor.cpp.

◆ applyColorMap() [2/2]

void cv::applyColorMap ( InputArray  src,
OutputArray  dst,
InputArray  userColor 
)

#include <opencv2/imgproc.hpp>

Applies a user colormap on a given image.

Parameters
srcThe source image, grayscale or colored of type CV_8UC1 or CV_8UC3.
dstThe result is the colormapped source image. Note: Mat::create is called on dst.
userColorThe colormap to apply of type CV_8UC1 or CV_8UC3 and size 256