One approach is to take the average brightness of a set of pixels in your image. If you have an image with RGB pixels, you can get the brightness by adding weighted components. The total weight is 30% red, 59% green, 11% blue:
brightness = pixel.red * 0.3 + pixel.green * 0.59 + pixel.blue * 0.11;
Depending on the variations of your image, how accurate the required measure, the resolution of your image, etc., you can average the sample of pixels around the image or simply average all of them.
source
share