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:
- COLORMAP_AUTUMN = 0
- COLORMAP_BONE = 1
- COLORMAP_JET = 2
- COLORMAP_WINTER = 3
- COLORMAP_RAINBOW = 4
- COLORMAP_OCEAN = 5
- COLORMAP_SUMMER = 6
- COLORMAP_SPRING = 7
- COLORMAP_COOL = 8
- COLORMAP_HSV = 9
- COLORMAP_HOT = 11
- COLORMAP_PINK = 10
- COLORMAP_PARULA = 12
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.