To convert a color image to Grayscale image using OpenCV, we read the image into BufferedImage and convert it into Mat Object.
Syntax: File input = new File("digital_image_processing.jpg"); BufferedImage image = ImageIO.read(input);
To transform the image from RGB to Grayscale format by using method cvtColor() in the Imgproc class.
Imgproc.cvtColor(source mat, destination mat1, Imgproc.COLOR_RGB2GRAY);
Parameters: The method cvtColor() takes three parameters which are the source image matrix, the destination image matrix, and the color conversion type.
Input : Output :
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.