Home > Java > javaTutorial > body text

How to create a custom colormap in Java using OpenCV?

WBOY
Release: 2023-08-26 11:37:12
forward
1299 people have browsed it

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.

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");
   }
}
Copy after login

Input picture

How to create a custom colormap in Java using OpenCV?

Output

When executed, the above program generates the following output-

How to create a custom colormap in Java using OpenCV?

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template