How to decrease the Brightness of an image in OpenCV using C++?

The way of decreasing brightness is very similar to increasing brightness. The only difference is subtracting the 'Scalar (B, G, R)' from the image. Here, we are subtracting the scalar value to decrease the brightness.

The following program shows how to decrease the brightness of an image in OpenCV.


using namespace cv;
using namespace std;
int main() {
   Mat original; //Declaring a matrix to load the original image//
   Mat dimmer;//Declaring a matrix to load the image after changing the brightness//
   namedWindow("Original");//Declaring window to show the original image//
   namedWindow("Dimmer");//Declaring window to show the brighter image//
   original = imread("bright.jpg");
   dimmer = original - Scalar(80, 80, 80);//subtracting integer value to change the brightness//
   imshow("Original", original);//showing original image//
   imshow("Dimmer", dimmer);//showing brighter image//
   waitKey(0);//wait for keystroke//