Question

Is there a c++ function or an opencv library that can calculate the average log of the luminance of a given 8*8 block or total image? My aim is to calculate the average luminance and store it back in the block. Also, is there another way to calculate the overall luminance or average luminance in another scientific method that fits the human visual system? If someone can point me to a lib or function in c++ I would appreciate that.

Was it helpful?

Solution

To calculate the average luminance of an 8x8 block, centred at each pixel in an input greyscale image, you could perform a 2D convolution of that image with an 8x8 kernel containing the value 1/64 i.e. 1/(8*8) in each cell.

This is referred to as a normalised box filter / box blur.

You can then sample the resulting image e.g. at (x,y) to yield the average luminance of the 8x8 block centred at (x,y).

There is code in the OpenCV manual for a normalised box filter, with user selectable size.

http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/filter_2d/filter_2d.html

Regarding the 'log' of this value, you can then use OpenCV function cvLog to take the log of the filtered image and obtain your result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top