Converting CMYK to RGB - get red tint on image

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
ballpark
Posts: 3
Joined: 2013-01-07T12:48:55-07:00
Authentication code: 6789

Converting CMYK to RGB - get red tint on image

Post by ballpark »

I am trying to convert CMYK images (tif and jpg) to RGB. I am using ImageMagic version 6.8.0-10 2012-12-20 Q16 using this command:

Code: Select all

convert img_in.tif -colorspace RGB -quality 100 img_out.jpg
I find that almost all conversion approaches that I have tried (PIL, imagemagick, and merely opening the image in a browser) seem to cause the images to have a red tint. Converting the images in Photoshop doesn't seem to have the same red result.

I also tried with

Code: Select all

-profile "AdobeRGB1998.icc"
, and had the same problem.

update: The red tint is mainly on caucasian skin
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting CMYK to RGB - get red tint on image

Post by snibgo »

You probably don't need a "colorspace" command, but might need one or more "profile" commmands. Can you put a sample on a website somewhere and post the URL here?
snibgo's IM pages: im.snibgo.com
ballpark
Posts: 3
Joined: 2013-01-07T12:48:55-07:00
Authentication code: 6789

Re: Converting CMYK to RGB - get red tint on image

Post by ballpark »

Thanks so much for your help. Here's a link to the original. http://dl.dropbox.com/u/27227204/cmyk_img_in.tif
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting CMYK to RGB - get red tint on image

Post by snibgo »

This is a studio photo so with any luck one frame contains a colour chart. It's best to work from that, if you have it, otherwise it gets a bit subjective. Do you think his shirt was light blue or greyish-lilac? Windows Photo Viewer and Explorer think his shirt was greyish-lilac, but Gimp reckons it was blue.

The camera white balance was set to "manual", presumably by the photographer to match the studio lighting. I don't know what settings the Canon Eos Rebel XSi has. It might have none for studio lights, which tend to be warmer than daylight but cooler than domestic incandescent.

Exiftool says the colorspace is uncalibrated, so that's not much help. The image has already been processed by Photoshop CS3 (Mac) and CS4 (Windows). The file contains some private (Photoshop?) data, so who knows what that does.

The file already has gamma 2.2, so instead of converting to sRGB, we need to convert to RGB. This way, IM won't apply another gamma 2.2 in the conversion from RGB to sRGB.

(For best quality, save to a lossless format such as tiff.)

I tried the "official" way: convert to a new profile. I converted to RGB, either before or after removing profiles. I removed, in turn, 2 of the 3 embedded profiles, and either didn't or did convert to sRGB profile. I did all those saving as JPG, and repeated saving as TIFF. Visually, all the results are the same, with a blue shirt (like Gimp), and florid skin. Windows script:

Code: Select all

"%IMG%convert" cmyk_img_in.tif -profile "%IMG%sRGB.icc" -colorspace RGB +profile "*" c.jpg
"%IMG%convert" cmyk_img_in.tif -colorspace RGB +profile "*" c2.jpg
"%IMG%convert" cmyk_img_in.tif -strip -colorspace RGB c3.jpg
"%IMG%convert" cmyk_img_in.tif +profile "!xmp,*" -colorspace RGB c4.jpg
"%IMG%convert" cmyk_img_in.tif +profile "!iptc,*" -colorspace RGB c5.jpg
"%IMG%convert" cmyk_img_in.tif +profile "!8bim,*" -colorspace RGB c6.jpg

"%IMG%convert" cmyk_img_in.tif +profile "!xmp,*" -profile "%IMG%sRGB.icc" -colorspace RGB c7.jpg
"%IMG%convert" cmyk_img_in.tif +profile "!iptc,*" -profile "%IMG%sRGB.icc" -colorspace RGB c8.jpg
"%IMG%convert" cmyk_img_in.tif +profile "!8bim,*" -profile "%IMG%sRGB.icc" -colorspace RGB c9.jpg


"%IMG%convert" cmyk_img_in.tif -profile "%IMG%sRGB.icc" -colorspace RGB +profile "*" c.tiff
"%IMG%convert" cmyk_img_in.tif -colorspace RGB +profile "*" c2.tiff
"%IMG%convert" cmyk_img_in.tif -strip -colorspace RGB c3.tiff
"%IMG%convert" cmyk_img_in.tif +profile "!xmp,*" -colorspace RGB c4.tiff
"%IMG%convert" cmyk_img_in.tif +profile "!iptc,*" -colorspace RGB c5.tiff
"%IMG%convert" cmyk_img_in.tif +profile "!8bim,*" -colorspace RGB c6.tiff

"%IMG%convert" cmyk_img_in.tif +profile "!xmp,*" -profile "%IMG%sRGB.icc" -colorspace RGB c7.tiff
"%IMG%convert" cmyk_img_in.tif +profile "!iptc,*" -profile "%IMG%sRGB.icc" -colorspace RGB c8.tiff
"%IMG%convert" cmyk_img_in.tif +profile "!8bim,*" -profile "%IMG%sRGB.icc" -colorspace RGB c9.tiff
I think (but can't be sure) they are also all correct. But it nags me that MS tools show a less florid skin tone, generally reducing red, possibly also reducing saturation.
snibgo's IM pages: im.snibgo.com
ballpark
Posts: 3
Joined: 2013-01-07T12:48:55-07:00
Authentication code: 6789

Re: Converting CMYK to RGB - get red tint on image

Post by ballpark »

Thanks for all the work that you did! It's clearly not a trivial task.

From the original CMYK photo, I see some grey in his shirt, so maybe greyish-lilac. Unfortunately for this task, I am more of a programmer than a graphic designer, so I lack the eye for these kinds of things.

We photoshopped the image only to white out his eyes, but the studio may have also made edits.

We have potentially 15,000 different images like this one. All are taken from different studios. I did a random sampling from different studios of 15 or so, and for every straightforward conversion* that is done, there is always the red tint on the face. This appears whether viewing the image Mac OSX Preview, Firefox, and Chrome. I also have no idea why MS tools are reducing the florid skin tone.

Would it make sense to apply some kind of hue/saturation filter? If so, any recommendations for that?

Thanks again!


* straightforward conversion - opening the cmyk image in a browser, Python's PIL, imagemagic's convert -colorspace RGB
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting CMYK to RGB - get red tint on image

Post by snibgo »

If Photoshop has a batch facility, and can gives you the result you want, that seems the best route.


I have played with the image, trying to see what transformation the MS tools are applying. To my eye, the result is more "appealing" then the correct (I think) conversion. I don't think it's a straightforward colour balance (ie multiplying each channel by a number). I did get somewhere close with IM's "-color-matrix" filter. Windows "bat" script; adjust as appropriate for other script languages:

Code: Select all

"%IMG%convert" ^
  c.tiff ^
  -colorspace RGB ^
  -color-matrix ^
  ^" 0.80 0.15 0.20 0 0 0.10 ^
     0    0.75 0.1  0 0 0.05 ^
     0    0    0.65 0 0 0 ^
     0    0    0    1 0 0 ^
     0    0    0    0 1 0 ^
     0    0    0    0 0 1^" ^
  -colorspace sRGB ^
  cm.tiff
I got the numbers by trial-and-error. It clearly isn't the same result as from Windows tools, but to my eyes is more appealing than the correct conversion.

Note that this transformation is in RGB space, not sRGB. A result closer to Windows tools might be possible (with different numbers) by transforming in RGB space.

"-modulate" is a possibility for adjusting the colour balance and decreasing saturation, eg

Code: Select all

"%IMG%convert" c.tiff -modulate 100,70,115 cm2.tiff
is quite good, but has too much green.


Another route is to create a 3-D CLUT (colour lookup table) that does the transformation you want, and apply that to your 15,000 images. See http://www.imagemagick.org/Usage/color_mods/#color_lut

Step 1: Create a "hald clut":

Code: Select all

"%IMG%convert" hald:12 hald.png
Step 2: Using your favourite image editor (eg Photoshop or Gimp), apply whatever edits you want to c.tiff. You might adjust hue, saturation, color curves, whatever. Take a careful note of the edits. Save the result if you want, but it doesn't matter.

Step 3: Using the same editor, open hald.png. Apply exactly the same edits to this file. Save it as "haldEdited.png". (In Gimp, use "export".)

Step 4: Apply this clut:

Code: Select all

"%IMG%convert" c.tiff haldEdited.png -hald-clut c_clutted.tiff
The result should look exactly like your edits of c.tiff. You can then apply the same haldEdited.png to your 15,000 images.

(The exact filenames don't matter, of course. They are merely my conventions.)
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting CMYK to RGB - get red tint on image

Post by fmw42 »

I have not read all the posts here, but Photoshop has more settings it use for color conversion and profiles, in particular the Dot Gain.

Open the Color Settings panel and turn off dot gain, etc and see if that gives results closer to IM.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting CMYK to RGB - get red tint on image

Post by snibgo »

The following gives a result very close to the result from Windows tools. The most obvious difference is in the tie, which wasn't sampled by the software that created the transformation.

Code: Select all

"%IMG%convert" c.tiff ^
  -colorspace CIELab ^
  -channel R -function polynomial 0.847524,0.0554703 ^
  -channel G -function polynomial 0.514276,0.263686 ^
  -channel B -function polynomial 0.702814,0.182175 ^
  -channel RGB ^
  -colorspace HSL ^
  -channel G -function polynomial 1.04247,-0.0339157 ^
  -channel B -function polynomial 1.05593,-0.0101056 ^
  -colorspace sRGB ^
  c_quite_good.tiff
snibgo's IM pages: im.snibgo.com
Post Reply