Page 1 of 1
colorspace conversion woes
Posted: 2012-12-27T10:23:16-07:00
by mwk
Hi All-
I'm trying to convert some PNGs with a colorspace of SRGB to JPEGs with a colorspace of RGB but I'm having some problems. When comparing the results to the original files in OS X's Preview and Windows 7's Photo Viewer application, the results are very dark and to my eye almost monochrome.
Imagemagick is being called from an external process via it's command line interface. Here is the call. See
this link for an image that can duplicate these results and
this link for this command's output.
Code: Select all
C:\Users\Administrator\Documents\static_imagemagick\convert -verbose -colorspace RGB -resize 512x512 test pngs\Corecycle41Burndown 2.png -flatten \
-testOutput\test.jpg
What am I doing wrong? FYI, I'm far from an Imagemagick or image format expert. Also, on a semirelated note, are there any good introductory resources on the web for learning more about image format conversions/color profiles/etc? I feel it's likely that I'm having issues with this because I don't have a good grasp on the subject.
FYI this is on a windows 7 x64 box running the statically linked prebuilt IM available from the IM download page. Here's the output of convert -version:
Version: ImageMagick 6.8.0-10 2012-12-12 Q16
http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: OpenMP
thanks,
Mike
Re: colorspace conversion woes
Posted: 2012-12-27T11:51:11-07:00
by snibgo
Before tackling the apparent problem, can I ask why you want to convert from sRGB to RGB? Most software assumes JPEG files are in sRGB space. JPEGS should almost always be in sRGB. Perhaps your application really needs them to be RGB, but I find this unlikely.
Incidentally, your command should generally be...
Code: Select all
convert -verbose inputfile {conversion options} outputfile
... not with the conversion option before the input file.
EDIT: correction to my above: I seem to recall that JPEGs don't contain a flag that specifies the colorspace, so they should always be interpreted as sRGB. The conversion from sRGB to RGB will lower the pixel numbers, but any software will interpret these as sRGB, not RGB, values. So your picture looks darker.
Re: colorspace conversion woes
Posted: 2012-12-27T11:55:46-07:00
by glennrp
Verified the "dark" output with IM-6.8.1-3 when writing to jpg or txt. But when writing to ppm the image is as bright as the input.
The input has a bad CRC in the iTXt chunk but that warning can be ignored; it has nothing to do with the color rendering.
Re: colorspace conversion woes
Posted: 2012-12-27T11:55:51-07:00
by fmw42
First, you should read the input image right after the convert command for non-vector images in IM 6 as correct syntax. see
http://www.imagemagick.org/Usage/basics/#why
Second, jpg does not support RGB colorspace, so IM will list sRGB even after your convert, but will apply the gamma change to make the colors linear before resizing. Thus it looks too dark. Either use -set colorspace RGB in place of -colorspace RGB or leave -colorspace RGB out altogether. see
http://www.imagemagick.org/script/color-management.php
Third, you png file is corrupt in some way as I get the following error message when using convert or identify -verbose.
convert: iTXt: CRC error `Corecycle41Burndown 2.png' @ warning/png.c/MagickPNGWarningHandler/1777.
I do not know what that means or if significant.
P.S.
Sorry Snibgo and Glenn, I was posting at about the same time. You have covered the same answers and more.
Re: colorspace conversion woes
Posted: 2012-12-27T13:27:00-07:00
by mwk
Hmm...I think I understand. The application calling imagemagick used to call out to a much older version of imagemagick (it has since been updated) and now I vaguely remember reading something about older Imagemagick releases having RGB and sRGB backwards-. So if you wanted output to be RGB, you had to send it a sRGB flag? Does this make sense?
Either way, setting the output colorspace on JPEG conversion to sRGB seems to do the trick.
Re: colorspace conversion woes
Posted: 2012-12-27T15:10:52-07:00
by fmw42
[quote="mwk"]Hmm...I think I understand. The application calling imagemagick used to call out to a much older version of imagemagick (it has since been updated) and now I vaguely remember reading something about older Imagemagick releases having RGB and sRGB backwards-. So if you wanted output to be RGB, you had to send it a sRGB flag? Does this make sense?
Yes, that is true. RGB and SRGB were backwards in older versions of IM. Input color images are now seen as sRGB unless the format supports something special such as RGB, LAB, etc. IM will output to sRGB now. So in your case your input png was sRGB and the output without adding -colorspace will be sRGB for jpg. So all you need to do is the resize.
The changes took place as noted at
http://www.imagemagick.org/script/color-management.php