Color maps in OpenCV

In order to perform this transformation, OpenCV has several color maps to enhance visualization. The cv2.applyColorMap() function applies a color map on the given image. The color_map_example.py script loads a grayscale image and applies the cv2.COLORMAP_HSV color map, as shown in the following code:

img_COLORMAP_HSV = cv2.applyColorMap(gray_img, cv2.COLORMAP_HSV)

Finally, we are going to apply all the color maps to the same grayscale image and plot them in the same figure. This can be seen in the color_map_all.py script. The color maps that OpenCV has defined are listed as follows:

The color_map_all.py script applies all these color maps to a grayscale image. The output of this script can be seen in the following screenshot:

In the previous screenshot, you can see the effect of applying all the predefined color maps to a grayscale image with the objective of enhancing the visualization.