converting a png with an ICC profile?

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
jedierikb
Posts: 20
Joined: 2012-12-13T13:59:27-07:00
Authentication code: 6789

converting a png with an ICC profile?

Post by jedierikb »

I can convert a jpg from one ICC to another ICC.

[code]convert rgb_image.jpg -profile USCoat.icm cmyk_image.jpg[/code]

Or I can convert a jpg with no ICC to another ICC.

[code] convert rgb_image.jpg +profile icm \
-profile sRGB.icc -profile USCoat.icm cmyk_image.jpg[/code]

But how do I convert a png's pixels into the gamut described by an ICC profile? I understand I cannot embed the profile into the image file, but would at least like to convert the colors.

When I reuse the above commands, the colors come out wrong... (different from the same colors in the JPG when converted).

Any suggestions?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting a png with an ICC profile?

Post by snibgo »

I'm not sure if I understand the question, but I'll have a go at answering it.

If an input file has no embedded profile, "-profile" will just add a new embedded profile. If it already has one, the pixel values will change to transform from the new to the old profile, and the new profile will be embedded, replacing the old one.

Code: Select all

convert rose: -strip rose.png
... creates a PNG with no profile.

Code: Select all

convert -verbose rose.png -profile sRGB.icc -profile snibgoGBR.icc +profile * roseGBR.png
... embeds the sRGB profile (which would have no effect as the image is already sRGB), then applies the snibgoGBR profile (which is designed to reverse the R and G channels). This second "-profile" will change pixel values. "+profile *" removes all embedded profiles.

Voila: a green rose.
snibgo's IM pages: im.snibgo.com
jedierikb
Posts: 20
Joined: 2012-12-13T13:59:27-07:00
Authentication code: 6789

Re: converting a png with an ICC profile?

Post by jedierikb »

This is the source image:
http://alumni.media.mit.edu/~erikb/tmp/RED_JPG.jpg

And here is what I am trying:

Code: Select all

convert RED_JPG.jpg +profile icm -profile sRGB_v4_ICC_preference.icc -profile USWebUncoated.icc CMYK_PNG.png
and this is what I am getting:
http://alumni.media.mit.edu/~erikb/tmp/CMYK_PNG.png

I was hoping to get an image with the same colors as a JPEG run through the same command:

Code: Select all

convert RED_JPG.jpg +profile icm -profile sRGB_v4_ICC_preference.icc -profile USWebUncoated.icc CMYK_JPG.jpg
resulting in:
http://alumni.media.mit.edu/~erikb/tmp/CMYK_JPG.jpg

this image, CMYK_JPG.jpg, is what I am trying to reproduce pixel for pixel in a PNG file.
Last edited by jedierikb on 2012-12-13T17:54:38-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting a png with an ICC profile?

Post by snibgo »

jedierikb wrote:this image, CMYK_JPG.jpg, is what I am trying to reproduce pixel by pixel in a PNG file.
Sorry, I don't understand. The pixel values will be different. The JPG file is CMYK. The PNG file is RGB. The pixel values will be different.
snibgo's IM pages: im.snibgo.com
jedierikb
Posts: 20
Joined: 2012-12-13T13:59:27-07:00
Authentication code: 6789

Re: converting a png with an ICC profile?

Post by jedierikb »

I appreciate the confusion.

In photoshop I can open the rgb jpg and save it as a png, and then reopen that png and covert it to an icc cmyk profile. When I save that png, it's colors are what I am trying to match.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting a png with an ICC profile?

Post by snibgo »

So, you have an RGB file and a CMYK file, and you are trying to match the colours on the screen. Is that correct? If so, why? CMYK is for printing; RGB is for screens. The gamuts overlap but each has colours that can't be reproduced in the other.

Your RED_JPG.jpg is very nearly pure red, and pure colours are where the gamuts don't overlap.
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: converting a png with an ICC profile?

Post by glennrp »

jedierikb wrote: I understand I cannot embed the profile into the image file, but...
"convert" does in fact embed the ICC profile into the PNG file, as the iCCP chunk. However, if
the profile is recognized to be sRGB then it only embeds an "sRGB" chunk. Any PNG
decoder finding the sRGB chunk is supposed to expand it back to the sRGB ICC profile.
jedierikb
Posts: 20
Joined: 2012-12-13T13:59:27-07:00
Authentication code: 6789

Re: converting a png with an ICC profile?

Post by jedierikb »

I am building an application, wherein different images, of different formats, can be composited on top of each other. This is so the user can get a preview of the composition.

The resultant composition, exported when the user is satisfied with their composition, will always be in a specific ICC profile for printing.

The way the composition system is architected, I need each layer to look like it is in the specific ICC profile so that the user can get a quick preview of what the final image will be (stacked in the right z-order). I am also planning to show the layers in a 3-d mode too (sort of like an old-type pop-up book).

If all of the layers were opaque, I could just stick with JPEGs and be done. But since I need to support alpha channels in the composition, I am looking for a way to convert PNGs with an alpha channel so they look like they are in the same gamut.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting a png with an ICC profile?

Post by snibgo »

Okay. This general procedure, of displaying CMYK files on screen, is known as "softproofing". A couple of good introductions on how to do it in Photoshop:

http://www.cambridgeincolour.com/tutori ... oofing.htm
http://www.luminous-landscape.com/tutor ... fing.shtml

Those pages discuss how photographers do it. Requirements for other mediums differ; sometimes high saturation should be maintained at the expense of hue or tone.
snibgo's IM pages: im.snibgo.com
jedierikb
Posts: 20
Joined: 2012-12-13T13:59:27-07:00
Authentication code: 6789

Re: converting a png with an ICC profile?

Post by jedierikb »

Thank you, I will look more into subproofing.

However, as I mentioned, I am alredy able to accomplish the specific task I am trying to accomplish already in Photoshop. The steps: I can open a PNG, Convert to Profile [ICC], and save as PNG. When I re-open the resultant png, its pixels look right.

Surely there is a way to replicate these steps in ImageMagick?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting a png with an ICC profile?

Post by fmw42 »

Open your file in PS, then go to the Color Settings in Photoshop and open that window. Note what profiles are set and also the Dot Gain. I suspect that the Dot Gain is changing things in PS and you would either need to turn off the Dot Gain and save. Then possibly IM will be able to match that with the very same profiles. Search Google for Dot Gain and Photoshop to see more details.
jedierikb
Posts: 20
Joined: 2012-12-13T13:59:27-07:00
Authentication code: 6789

Re: converting a png with an ICC profile?

Post by jedierikb »

I think I am able to accomplish what I set out to do, albeit without alpha channel support, with these steps:

Code: Select all

convert src_rgb.png src_rgb.jpg

convert src_rgb.jpg +profile icm -profile sRGB_v4_ICC_preference.icc -profile USWebUncoated.icc src_cmyk.jpg

convert -profile sRGB_v4_ICC_preference.icc src_cmyk.jpg dest_cmyk.png
dest_cmyk.png is a file whose pixels are in the USWebUncoated.icc gamut. It is, unfortunately, missing an alpha channel (if there was one in the original PNG).

Is there an easier way to bundle these three commands into one? And any ideas on the alpha channel?
jedierikb
Posts: 20
Joined: 2012-12-13T13:59:27-07:00
Authentication code: 6789

Re: converting a png with an ICC profile?

Post by jedierikb »

and, to add the opacity back to the converted image:

Code: Select all

convert dest_cmyk.png src_rgb.png -compose copy-opacity -composite dest_cmyk_alpha.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting a png with an ICC profile?

Post by fmw42 »

You lose your transparency when converting from png to jpg in your first step, because jpg does not support transparency. You will need to copy the alpha channel from your original png and save it for later combining with your final png image.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting a png with an ICC profile?

Post by snibgo »

You might also find that tiff is a useful format for your purpose. It can store CMYK and alpha channels.
snibgo's IM pages: im.snibgo.com
Post Reply