Search code examples
imagemagickgamma

Output the calculated gamma in ImageMagick -auto-gamme option


I need to know the level of gamma correction that ImageMagick is automatically computing when we use the following command

convert in.jpg -auto-gamma out.jpg

Is that possible?

Thank you


Solution

  • If I remember correctly, -auto-gamma would call the AutoGammaImage method, and apply the following equation.

    gamma = log(pixel_mean)/log(0.5)
    

    So to calculate what value of gamma correction will be applied, you can do something like...

     pixel_mean=$(identify -format '%[mean]' rose:)
     echo "l($pixel_mean)/l(0.5)" | bc -l
     #=> -14.72189
    

    As Mark pointed out in the comments, you can also use ImageMagick FX language to calculate.

    identify -format '%[fx:ln(mean*QuantumRange)/ln(0.5)]' rose:
    #=> -14.7219