adjust image brightness/contrast using c++ without using any other 3rd party library or dependancy
adjust image brightness/contrast using c++ without using any other 3rd party library or dependancy
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Image brightness is here – use the mean of the RGB values and shift them.
Contrast is here with other languages solutions available as well.
Edit in case the above links die:
The answer given by Jerry Coffin below covers the same topic and has links that still live.
But, to adjust brightness, you add a constant value to each for the R,G,B fields of an image. Make sure to use saturated math – don’t allow values to go below 0 or above the maximum allowed in your bit-depth (8-bits for 24-bit color)
For contrast, I have taken and slightly modified code from this website:
Where
truncate(int value)makes sure the value stays between 0 and 255 for 8-bit color. Note that many CPUs have intrinsic functions to do this in a single cycle.