Convert color values from RGB to CMYK with 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?".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert color values from RGB to CMYK with ICC profile

Post by snibgo »

Well spotted. I have reported it: viewtopic.php?f=3&t=25633
snibgo's IM pages: im.snibgo.com
tricon
Posts: 13
Joined: 2014-05-20T01:31:52-07:00
Authentication code: 6789

Re: Convert color values from RGB to CMYK with ICC profile

Post by tricon »

Cool.
I will simply work with the swapped values meantime.

Thanks for the great help :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert color values from RGB to CMYK with ICC profile

Post by snibgo »

The bug occurs when "m" and "y" are used explicitly. Compare and contrast:

convert xc:cmyk(10%,20%,30%,40%) -colorspace CMYK -precision 9 -format "%[fx:100*p{0,0}.c]\%,%[fx:100*p{0,0}.m]\%,%[fx:100*p{0,0}.y]\%,%[fx:100*p{0,0}.k]\%\n" info:

10.000763%,30.000763%,20%,40%

convert xc:cmyk(10%,20%,30%,40%) -colorspace CMYK -precision 9 -format "%[pixel:p{0,0}]\n" info:

cmyk(10.000763%,20%,30.000763%,40%)

EDIT: This is a reply to a post that then vanished.
snibgo's IM pages: im.snibgo.com
sera88
Posts: 5
Joined: 2015-08-01T04:21:01-07:00
Authentication code: 1151

Re: Convert color values from RGB to CMYK with ICC profile

Post by sera88 »

Hi Everyone,

sorry for warming this thread up, but i ran into the same trouble with the exact behaviour.
I tried the upper commands and they work like expected, but the color seems not to be similar like photoshop.
If i run the following command i get cmyk(100,0,0,0) instead of cmyk(80,24,0,0):

Code: Select all

convert xc:rgb\(0,255,255\) -precision 9 -colorspace cmyk -format "%[fx:int(100*c)], %[fx:int(100*m)], %[fx:int(100*y)], %[fx:int(100*k)]\r\n" info:
can someone maybe share some insights how i get the right conversion like in the upper post from Tricon?

Thanks in advance,
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert color values from RGB to CMYK with ICC profile

Post by snibgo »

See upthread. Tricon was using "-profile" for the conversions, not "-colorspace".
snibgo's IM pages: im.snibgo.com
sera88
Posts: 5
Joined: 2015-08-01T04:21:01-07:00
Authentication code: 1151

Re: Convert color values from RGB to CMYK with ICC profile

Post by sera88 »

wow thanks for the fast reply! :)

i tried it also with the profile:

Code: Select all

convert xc:'rgb(0,255,255)' -profile AdobeRGB1998.icc -profile CoatedFOGRA39.icc -precision 9 -format "%[fx:int(100*c)], %[fx:int(100*m)], %[fx:int(100*y)], %[fx:int(100*k)]\r\n" info:
but if i do so, i get the following i get the following:

Code: Select all

convert: delegate library support not built-in `rgb(0,255,255)' (LCMS) @ warning/profile.c/ProfileImage/849.
convert: ColorSeparatedImageRequired `' @ error/fx.c/FxGetSymbol/1647.
0, 100, 100, 
any ideas, what i can do?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Convert color values from RGB to CMYK with ICC profile

Post by Bonzo »

What operating system are you using and what version of Imagemagick?

Have you tried something simple to ensure Imagemagick is working on your setup?
sera88
Posts: 5
Joined: 2015-08-01T04:21:01-07:00
Authentication code: 1151

Re: Convert color values from RGB to CMYK with ICC profile

Post by sera88 »

Hi Bonzo,

Its a Imagemagick on a OSX, handled over the Terminal-application. simple image generations are working.
Version: ImageMagick 6.9.1-4

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

Re: Convert color values from RGB to CMYK with ICC profile

Post by snibgo »

What does "convert -version" say? It should be something like:

Code: Select all

Version: ImageMagick 6.9.1--6 Q16 x64 2015-06-20 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib
If it doesn't say lcms under delegates, that's the problem.
snibgo's IM pages: im.snibgo.com
sera88
Posts: 5
Joined: 2015-08-01T04:21:01-07:00
Authentication code: 1151

Re: Convert color values from RGB to CMYK with ICC profile

Post by sera88 »

Hi snibgo,

THX so much! after reinstall of ImageMagick with littleCMS it works like charme now!! :)
sera88
Posts: 5
Joined: 2015-08-01T04:21:01-07:00
Authentication code: 1151

Re: Convert color values from RGB to CMYK with ICC profile

Post by sera88 »

Ok, now i'm facing the last problem of the overall topic.

I get now from rgb(0,255,255) the following cmyk(56,0,18,0) value, what is obvious the right one like in photoshop.
But now i need to reconvert it into the right rgb value to visualize it to the customer.

i tried the following:

Code: Select all

convert xc:'cmyk(56,0,18,0)' -profile CoatedFOGRA39.icc -profile sRGB.icc -precision 9 -format "%[fx:int(100*r)], %[fx:int(100*g)], %[fx:int(100*b)]\r\n" info:
but it gives me rgb(81, 91, 94) back what is not correct. It should be something like rgb(85,198,212).

do anyone already figured out how this works?

Best,
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert color values from RGB to CMYK with ICC profile

Post by fmw42 »

The issue is that you have specified cmyk values in the range 0 to 255, but are requesting results in %. Note that in fx, r=u.r and either is in the range of 0 to 1. So your results are percent and not raw values. To get correspondence, multiply by 255 or use 100 and add %. I am using IM 6.9.1.10 Q16 Mac OSX

Code: Select all

convert xc:'cmyk(56,0,18,0)' \
-set colorspace CMYK -colorspace sRGB \
-precision 4 -format "%[fx:100*r]\%, %[fx:100*g]\%, %[fx:100*b]\%\n" info:
78.04%, 100%, 92.94%

Code: Select all

convert xc:'cmyk(56,0,18,0)' \
-set colorspace CMYK -colorspace sRGB \
-format "%[fx:int(255*r)], %[fx:int(255*g)], %[fx:int(255*b)]\n" info:
199, 255, 237

Code: Select all

convert xc:'cmyk(56,0,18,0)' \
-set colorspace CMYK -colorspace sRGB \
 %[pixel:u.p{0,0}]\n" info:
srgb(199,255,237)

All these results agree with results from the color converter at http://www.imagemagick.org/contrib/color-converter.php

Using profiles will give slightly different result, depending upon the profiles used. For example:

Code: Select all

convert xc:'cmyk(56,0,18,0)' \
-set colorspace CMYK -profile /users/fred/images/profiles/USWebCoatedSWOP.icc \
-profile /users/fred/images/profiles/sRGB.icc \
-format "%[fx:int(255*r)], %[fx:int(255*g)], %[fx:int(255*b)]\n" info:
195, 231, 235
Post Reply