A method for estimating the best gamma value for an RGB image is described. The algorithm is intended to be part of a larger image enhancement system. It first quantizes the image colors into a small palette and then finds the gamma that distributes the palette colors most evenly in a modeled perceptual lightness scale, which adapts to the overall image luminance. The algorithm was tested both against gammas assumed to be correct and subjectively optimal gammas. The estimated gamma offers no statistical advantage when a reliable correct gamma is known, but when one is not available, the algorithm can be used to select gammas that correlate with the subjective optimum to a degree comparable to differences between individual subjects.
Juha Katajamäki, Pekka Laihanen, "Image Dependent Gamma Selection Based on Color Palette Equalization and a Simple Lightness Model" in Proc. IS&T 7th Color and Imaging Conf., 1999, pp 301 - 306, https://doi.org/10.2352/CIC.1999.7.1.art00057