$darkmode
OpenCV 4.12.0
Open Source Computer Vision
Enumerations | Functions
ColorMaps in OpenCV

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>
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;
}
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
Loads an image from a file.
void applyColorMap(InputArray src, OutputArray dst, int colormap)
Applies a GNU Octave/MATLAB equivalent colormap on a given image.
@ COLORMAP_JET
Definition: imgproc.hpp:4528
int main(int argc, char *argv[])
Definition: highgui_qt.cpp:3
Definition: affine.hpp:52
See also
ColormapTypes

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 ,
  cv::COLORMAP_TURBO = 20 ,
  cv::COLORMAP_DEEPGREEN = 21
}
 GNU Octave/MATLAB equivalent colormaps. More...
 

Functions

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

Enumeration Type Documentation

◆ ColormapTypes

#include <opencv2/imgproc.hpp>

GNU Octave/MATLAB equivalent colormaps.

Enumerator
COLORMAP_AUTUMN 
Python: cv.COLORMAP_AUTUMN

COLORMAP_BONE 
Python: cv.COLORMAP_BONE

COLORMAP_JET 
Python: cv.COLORMAP_JET

COLORMAP_WINTER 
Python: cv.COLORMAP_WINTER

COLORMAP_RAINBOW 
Python: cv.COLORMAP_RAINBOW

COLORMAP_OCEAN 
Python: cv.COLORMAP_OCEAN

COLORMAP_SUMMER 
Python: cv.COLORMAP_SUMMER

COLORMAP_SPRING 
Python: cv.COLORMAP_SPRING

COLORMAP_COOL 
Python: cv.COLORMAP_COOL

COLORMAP_HSV 
Python: cv.COLORMAP_HSV

COLORMAP_PINK 
Python: cv.COLORMAP_PINK

COLORMAP_HOT 
Python: cv.COLORMAP_HOT

COLORMAP_PARULA 
Python: cv.COLORMAP_PARULA

COLORMAP_MAGMA 
Python: cv.COLORMAP_MAGMA

COLORMAP_INFERNO 
Python: cv.COLORMAP_INFERNO

COLORMAP_PLASMA 
Python: cv.COLORMAP_PLASMA

COLORMAP_VIRIDIS 
Python: cv.COLORMAP_VIRIDIS

COLORMAP_CIVIDIS 
Python: cv.COLORMAP_CIVIDIS

COLORMAP_TWILIGHT 
Python: cv.COLORMAP_TWILIGHT

COLORMAP_TWILIGHT_SHIFTED 
Python: cv.COLORMAP_TWILIGHT_SHIFTED

COLORMAP_TURBO 
Python: cv.COLORMAP_TURBO

COLORMAP_DEEPGREEN 
Python: cv.COLORMAP_DEEPGREEN

Function Documentation

◆ applyColorMap() [1/2]

void cv::applyColorMap ( InputArray  src,
OutputArray  dst,
InputArray  userColor 
)
Python:
cv.applyColorMap(src, colormap[, dst]) -> dst
cv.applyColorMap(src, userColor[, dst]) -> dst

#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. If CV_8UC3, then the CV_8UC1 image is generated internally using cv::COLOR_BGR2GRAY.
dstThe result is the colormapped source image of the same number of channels as userColor. Note: Mat::create is called on dst.
userColorThe colormap to apply of type CV_8UC1 or CV_8UC3 and size 256

◆ applyColorMap() [2/2]

void cv::applyColorMap ( InputArray  src,
OutputArray  dst,
int  colormap 
)
Python:
cv.applyColorMap(src, colormap[, dst]) -> dst
cv.applyColorMap(src, userColor[, dst]) -> dst

#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. If CV_8UC3, then the CV_8UC1 image is generated internally using cv::COLOR_BGR2GRAY.
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.