1. Theory
The transformation of the image is to transform each pixel in the image to get a new pixel and a new image.
Change the contrast and brightness of the picture as follows:
where α and β are called gain parameters (gain parameter) and deviation parameters (bias parameter), respectively, control contrast and brightness.
2. Implementing the Code
The code for changing contrast and brightness using the above formula is as follows:
voidContrastandbrightness (Constmat& src,mat& Dst,DoubleAlphaDoubleBeta) {Dst=Mat::zeros (Src.size (), Src.type ()); for(inty =0; Y < src.rows; y++) { for(intx =0; x < Src.cols; X + +) { for(intc =0; C <3; C++) {dst.at<Vec3b> (Y,X) [c] = saturate_cast<uchar> (Alpha * (src.at<vec3b> (Y,X) [C]) +beta); }}} Namedwindow ("SRC Image"); Namedwindow ("Dst Image"); Imshow ("SRC Image", SRC); Imshow ("Dst Image", Dst); Waitkey ();}
Use the OpenCV self-bringing function to handle the following:
Src.convertto (Dst,-12.2);
3. Processing results
The following are the results of the processing of the alpha setting of 1.5,beta to 30 o'clock, and the results of the processing are not as many as possible, but the functions provided by OPENCV are called as much as you use.
4. End
OpenCV Getting Started: (V: Change picture contrast and brightness)