The
Imgproc class's applyColorMap() method applies the specified color map to the given image. This method accepts three parameters -
Two Mat objects representing the source image and the target image.
An integer variable representing the type of colormap to apply.
You can pass any of the following values to this method as a colormap value.
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.
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"); } }
When executed, the above program generates the following output-
The above is the detailed content of How to create a custom colormap in Java using OpenCV?. For more information, please follow other related articles on the PHP Chinese website!