Page 1 of 1

ImageMagick >6.7 : How convert any image (.png) to sRGB colorspace properly?

Posted: 2018-12-08T07:39:08-07:00
by otoha
Hello everyone !


Despite long hours spent reading the documentation and various trial, I could not solve the following simple problem (IM version >=6.7).

How, given any image (grayscale, sRGB , .... ) with any gamma (1, 0.4545 , ....) can one convert it to a final image with fixed gamma, in sRGB colorspace, 8 bits, while keeping the original appearance ?

This would infinitely simplify appending different images in a later afterwards.

I tried many things and syntaxes, including channels splitting and then recombine, auto-level, etc ... but to no avail .....

Please help me see the magick in IM : )

Thank you in advance, Cheers

PS: This a copy of my question posted on stackoverflow

https://stackoverflow.com/questions/536 ... e-properly

Re: ImageMagick >6.7 : How convert any image (.png) to sRGB colorspace properly?

Posted: 2018-12-08T10:45:53-07:00
by snibgo
It's not a simple problem. I suggest the following:

1. If the image has an embedded ICC profile, convert it with "-profile" to an sRGB profile. There are plenty to choose from, all slightly different. Whichever one you choose, leave it embedded, don't "-strip" it. The job is done.

2. There is no embedded profile. Is the image colour model RGB, CMYK, or something else?

3. RGB: Is the gamma around 0.4545, 1,0 or something else?

3a RGB gamma around 0.4545: assume the image is encoded as sRGB, and assign an ICC sRGB profile. Which one is correct for your image? Who knows.

3b RGB gamma 1.0: assume the image is encoded as linear sRGB. Convert it to non-linear sRGB and assign a profile, like ths:

Code: Select all

magick in.ext -set colorspace RGB -colorspace sRGB -profile youchoose.icc out.ext
3c RGB some other gamma: who knows? Perhaps do a gamma conversion to make it 1.0, then proceed as "RGB gamma 1.0" above.

4. CMYK: Complain to whoever made the image that there is no embedded profile. Then assign an ICC CMYK profile. Which one is correct for your image? Who knows. I suspect the origin might help; I think the USA commonly uses USWeb profiles, but Fogra is more popular in Europe and Japan. But I have little experience.

After assigning a CMYK profile, convert it to an sRGB profile.

5. The colour model isn't RGB or CMYK. With luck, it is something IM understands, like XYZ or xyY or Lab. Use "-colorspace sRGB" to convert it to sRGB, then assign an sRGB profile.

Re: ImageMagick >6.7 : How convert any image (.png) to sRGB colorspace properly?

Posted: 2018-12-09T04:23:34-07:00
by otoha
Thanks a lot for your complete answer.

Apparently, for now, adding a -define png:color-type=2 as a first step to transform all images, then later a -colorspace sRGB when i append the results seems to work.


Thank you !