imagemagickpngimagemagick-convertgamma

How can I fix PNG's gamma using ImageMagick?


I'd like to fix a PNG's gamma value to 1/2.2. For example, let's say there is a png image whose gAMA value is 1/4.4. For some reasons, I have to fix the value to 1/2.2. So I try convert command like below.

# 0.5 is led by (1/4.4)/(1/2.2)
# 0.45455 is led by 1/2.2
$ convert orig.png -gamma 0.5 +gamma 0.45455 new.png

Then, I compare two images, orig.png and new.png, but they appear to be different.

I guess the formula, (1/4.4)/(1/2.2), is wrong. Does anyone know the correct way to do it?

Thanks.

EDITED:

Sorry, but maybe I could not tell you what I really want to do. So, I added more information and sample images.

First of all, I have the below image. This image's gAMA is about 0.227(1/4.4). This image's gAMA value is 0.227(1/4.4)

And then, I need this image. The image's gAMA is 0.4545(1/2.2) but the appearance is same as the above one.

This image is what I want

So, I don't need this. This image's gAMA is also 0.4545(1/2.2), but the appearance is different from the first one.

This image's gAMA value is 0.4545(1/2.2)


Solution

  • This seems to work for me in Imagemagick.

    convert red44.png -gamma 0.5 -set gamma 0.4545 red22_new.png
    

    enter image description here

    identify -verbose red22_new.png
    

    ... Gamma: 0.4545 ...