Contrast means to change the value of each and every image pixel. This change can be done by either multiplying or dividing the pixel values of the image, by any constant. This article gives an in-depth knowledge about how can an image contrast be changed using OpenCV.
Input : Original Image Output : -> Original Image -> Image with contrast increased by 4 -> Image with contrast increased by 2 -> Image with contrast decreased by .5 -> Image with contrast decreased by .25
Code : CPP code to increase or decrease the contrast of an iamge
Image with contrast increased by 4
Image with contrast increased by 2
Image with contrast decreased by .5
Image with contrast decreased by .25
These code lines will change the image pixel values by a specified amount. The final changed image is then stored to the given output image. The contrast level will increase if the specified amount factor is greater than 1, otherwise will decrease if the specified amount factor is less than 1.
MAT Function :
The “MAT” function changes each image pixel value to the target data type and the values are changed as the degree of factor multiplied.
Parameters : m : Output Image rtype : Output Image type, Output Image type is same as input if it is set to -ve value alpha : Input image pixel are multiplied with this number prior to its assignment to output image beta : adding this value to each input image pixel
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- OpenCV | Understanding Contrast in an Image
- OpenCV | Hands on Image Brightness
- Image Processing in Java | Set 12 ( Contrast Enhancement )
- OpenCV | Displaying an Image
- OpenCV | Saving an Image
- Image Inpainting using OpenCV
- Image Steganography using OpenCV in Python
- Log transformation of an image using Python and OpenCV
- OpenCv | Coloured Blank Image
- OpenCV | Understanding Brightness in an Image
- Reading an image in OpenCV using Python
- OpenCV C++ Program to blur an image
- Image Processing without OpenCV | Python
- Image Translation using OpenCV | Python
- Image Registration 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.