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 :
- MATLAB | Converting a Grayscale Image to Binary Image using Thresholding
- MATLAB | RGB image to grayscale image conversion
- MATLAB | Complement colors in a Grayscale Image
- MATLAB | Display histogram of a grayscale Image
- Image Processing in Java | Set 4 (Colored image to Negative image conversion)
- Image Processing in Java | Set 6 (Colored image to Sepia image conversion)
- Image Processing in Java | Set 3 (Colored image to greyscale image conversion)
- Python OpenCV | cv2.cvtColor() method
- Image Processing in Java | Set 5 (Colored to Red Green Blue Image Conversion)
- Converting Text to Speech in Java
- Image Processing in Java | Set 7 (Creating a random pixel image)
- Image Processing in Java | Set 8 (Creating mirror image)
- Image Processing in Java | Set 11 (Changing orientation of image)
- Image Processing in Java | Set 10 ( Watermarking an image )
- Java.awt.image.RescaleOp Class in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet