In OpenCV, changing the brightness of an image is a very basic task to perform. By changing the image brightness, it is meant to change the value of each and every image pixel. This change can be done by either increasing or decreasing the pixel values of the image, by any constant.
To increase the brightness levels of the image, simply add a constant positive value to each and every image pixel.
Similarly if one wishes to decrease the brightness level of the image, then subtract a constant positive value for each and every image pixel.
Let’s take an assumption by considering the below-mentioned matrix as our image matrix with values of pixel ranging from 0 to 255 and let’s assume that the data type for this image is CV_8UC3
Increasing Brightness :
So. let’s suppose we wish to increase image brightness by a value of 60. Then we add 60 to each image pixel value but it is strictly forbidden to exceed the pixel range i.e. the allowed maximum limit is 255 and our pixel value should not increase 255. Suppose if in any case, this image pixel value exceeds 255, then it should be given the maximum allowed value only instead of the newly increased value.
Output (After increasing the image pixel value by 60):
Let’s check the image matrix given below, we have increased this value by 60 but the pixel value “255” has not been increased to 260 as we add 60 to 200, it should be 260 but this is not happening here because the maximum image pixel value is allowed to be 255 in this image.
Decreasing Brightness :
Here, we are decreasing the pixel values by 20 and to do so 20 is subtracted from each and every image pixel in the input image but the only thing important is that the value of any pixel should not go below the minimum allowed pixel.
Output (After decreasing the image pixel value by 20):
As here in our output image, the brightness is decreased by 20 and at the location (0, 0), the pixel value equals 0 but earlier this value was 12. Because subtraction of 20 from 12 will give a negative pixel value (which can not be possible). So, the image pixel value is set to 0.
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- Image Processing using OpenCV in Java | Set 13 (Brightness Enhancement)
- OpenCV | Hands on Image Brightness
- OpenCV | Understanding Contrast in an Image
- Node Jimp | brightness
- Python PIL | ImageEnhance.Brightness() and ImageEnhance.Sharpness() method
- 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)
- OpenCV C++ Program to create a single colored blank image
- OpenCV C++ Program to blur an image
- OpenCV Python Program to analyze an image using Histogram
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Image Processing using OpenCV in Java | Set 14 ( Sharpness Enhancement )
- Reading an image in OpenCV using Python
- Python | Detect corner of an image using OpenCV
- Image Pyramid using OpenCV | Python
- Python | OpenCV program to read and save an Image
- Image Processing without OpenCV | Python
- Python | Image blurring using OpenCV
- Image Resizing using OpenCV | Python
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.