Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect the brightness programmatically

I am creating an application for iPad which can change the images by detecting the brightness of the room. So I want to know is there a way to detect the brightness of the room ?

like image 630
Lena Avatar asked May 01 '26 03:05

Lena


1 Answers

One approach is to take the average brightness of some set of pixels in your image. If you have an image with RGB pixels, you can get the brightness by adding the weighted components. A common weighting is 30% red, 59% green, 11% blue:

brightness = pixel.red * 0.3 + pixel.green * 0.59 + pixel.blue * 0.11;

Depending on the variations in your image, how accurate a measure you need, the resolution of your image, etc. you can average a sample of pixels from around the image, or just average all of them.

like image 188
verdesmarald Avatar answered May 04 '26 00:05

verdesmarald



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!