How to convert colored image to HLS using Java OpenCV library?



You can convert HLS image to RGB (colored) image by passing Imgproc.COLOR_RGB2HLS as the 3rd parameter to the cvtColor() method.

Example

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class HSL2RGB {
   public static void main(String args[]) throws Exception {
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
      Mat src = Imgcodecs.imread("D:\images\car3.jpg");
      Mat dst = new Mat();
      Imgproc.cvtColor(src, dst, Imgproc.COLOR_RGB2HLS);
      Imgcodecs imageCodecs = new Imgcodecs();
      imageCodecs.imwrite("D:\images\hslImage.jpg", dst);
      System.out.println("Image Saved");
   }
}

Input

Output


Advertisements