opencvContrast and Brightness in C++


Syntax

  • void cv::Mat::convertTo(OutputArray m, int rtype,double alpha = 1,double beta = 0)const

Parameters

ParameterDetails
moutput matrix; if it does not have a proper size or type before the operation, it is reallocated
rtypedesired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input
alphaoptional scale factor. This changes the contrast of an image. Values below 1 decrease the contrast and above one increases the contrast
betaoptional delta added to the scaled values. Positive values increases the brightness and negative values decreases the brightnes

Remarks

Contrast:

Contrast is the difference in luminance or colour that makes an object (or its representation in an image or display) distinguishable. The higher the difference between a pixel and its neighbors the higher the contrast is in that area.

Brightness:

In other words, brightness is the perception elicited by the luminance of a visual target. In terms of pixels, the higher the value of a pixel is the brighter that pixel is.

Contrast and Brightness adjustments:

g(i,j)= α.f(i,j)+β

f(x) as the source image pixels and g(x) as the output image pixels.

i and j indicates that the pixel is located in the i-th row and j-th column.

The parameters α > 0 and β are often called the gain and bias parameters; sometimes these parameters are said to control contrast and brightness respectively.

Opencv has a function called convertTo() which can apply these two operations.

Sources: http://docs.opencv.org/trunk/d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b http://opencv-srf.blogspot.ca/2013/07/change-contrast-of-image-or-video.html http://opencv-srf.blogspot.ca/2013/07/change-brightness.html