In this article we will learn how to enhance brightness of an image using OpenCv library. The brightness of an image can be enhanced by multiplying each pixel of the image with an alpha value and then adding a beta value to it.
At first we need to setup OpenCV for java, we recommend to use eclipse for the same since it is easy to use and setup. For installation refer here
Methods required for brightness enhancement:
- convertTo(destination, rtype, alpha, beta) : This method resides in Mat package of OpenCv.
sourceImage.convertTo(destination, rtype, alpha, beta); parameters: destination: is the destination image rtype: is the desired output matrix type alpha: is optional scale factor multiplied to each pixel of source image beta: it is optional beta value added to the scaled values.
- imread() – This method is used to read images as Mat objects which are rendered by OpenCV.
Imgcodecs.imread(filename); parameters: filename: filename of the image file.If the image is in another directory whole path of image must be mentioned.
- imwrite() – This method is used to write Mat objects to image file.
Imgcodecs.imwrite(filename, mat_img); parameters: filename: filename of the image file.If the image is in another directory whole path of image must be mentioned. mat_img: resultant mat object.
Note: The code will not work in online ide since it requires image in hard drive.
Alpha = 1, Beta = 50
Alpha = 2, Beta = 50
Alpha = 2, Beta = 25
This article is contributed by Pratik Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Image Processing using OpenCV in Java | Set 14 ( Sharpness Enhancement )
- Image Processing in Java | Set 12 ( Contrast Enhancement )
- OpenCV | Understanding Brightness in an Image
- OpenCV | Hands on Image Brightness
- Image Processing in Java | Set 3 (Colored image to greyscale image conversion)
- 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 without OpenCV | Python
- Image Processing in Java | Set 5 (Colored to Red Green Blue Image Conversion)
- 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 )
- Image Edge Detection Operators in Digital Image Processing
- Image processing with Scikit-image in Python
- Image Processing In Java | Set 2 (Get and set Pixels)
- Node Jimp | brightness
- Python PIL | ImageEnhance.Brightness() and ImageEnhance.Sharpness() method
- Image Processing in Java | Set 1 (Read and Write)
- Image Processing in Java | Set 9 ( Face Detection )