The applyColorMap() method of the Imgproc class applies specified color map to the given image. This method accepts three parameters −
Two Mat objects representing the source and destination images.
An integer variable representing the type of the color map to be applied.
You can pass any of the following as color map value to this method.
COLORMAP_AUTUMN, COLORMAP_BONE, COLORMAP_COOL, COLORMAP_HOT, COLORMAP_HSV, COLORMAP_JET, COLORMAP_OCEAN , COLORMAP_PARULA, COLORMAP_PINK, COLORMAP_RAINBOW, COLORMAP_SPRING, COLORMAP_SUMMER, COLORMAP_WINTER.
Example
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class CustomColorMaps { public static void main(String args[]) { // Loading the OpenCV core library System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // Reading the Image from the file and storing it in to a Matrix object String file ="D:\\images\\cat.jpg"; Mat src = Imgcodecs.imread(file); // Creating an empty matrix to store the result Mat dst = new Mat(); // Applying color map to an image Imgproc.applyColorMap(src, dst, Imgproc. COLORMAP_PINK); // Writing the image Imgcodecs.imwrite("D:\\images\\color_map.jpg", dst); System.out.println("Image processed"); } }
Input Image
Output
On executing, the above program generates the following output −