compute image contrast
There are many approaches to achieve this. For example, check the following work by Pederson et. al.:

Evaluation of contrast measures in relation to observers perceived contrast Marius Pedersen1, Alessandro Rizzi2, Jon Yngve Hardeberg1 and Gabriele Simone1.