OpenCV Getting Started: (V: Change picture contrast and brightness)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.