colorspace conversion woes

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mwk
Posts: 3
Joined: 2012-10-16T07:32:57-07:00
Authentication code: 67789

colorspace conversion woes

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: colorspace conversion woes

Post 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.
Last edited by snibgo on 2012-12-27T12:00:27-07:00, edited 1 time in total.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: colorspace conversion woes

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: colorspace conversion woes

Post 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.
mwk
Posts: 3
Joined: 2012-10-16T07:32:57-07:00
Authentication code: 67789

Re: colorspace conversion woes

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: colorspace conversion woes

Post 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
Post Reply