Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to estimate optimal gamma parameter for gamma correction?

Is it possible to estimate optimal gamma parameter for gamma correction by algorithm using some image statistics? By 'optimal' I mean that image should 'look good' for human on average after correction.

like image 613
mrgloom Avatar asked Oct 18 '25 18:10

mrgloom


1 Answers

If your image pixels are scaled on the range 0..255, you could use:

gamma = log(mean)/log(128)

where mean is the mean of your image pixels. If they are scaled on the range 0..1:

gamma = log(mean)/log(0.5)

Note that this is the technique that ImageMagick uses, documentation here, and you can test it yourself on the command line with:

magick input.jpg -auto-gamma result.jpg

Nothing is perfect though and that may not look good if there are heavy shadows or bright areas in your images.

like image 141
Mark Setchell Avatar answered Oct 22 '25 08:10

Mark Setchell



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!