Converting colors (not images) with ImageMagick

Specifically, I would like to accurately convert a CMYK value (possibly from space ISO Coated v2

) to an RGB value (perhaps from space sRGB

) on the Ruby platform (perhaps using ICC profiles).

ImageMagick seemed like a good place to start, but I also heard LittleCMS could be ported / wrapped to work with Ruby

.

Once again, I'm looking to convert image files without an image. Any ideas?

0


source to share


2 answers


In ImageMagick, you can do the following:



convert xc:"cmyk(0,255,255,0)" -colorspace sRGB -format "%[pixel:u.p{0,0}]\n" info:
red

convert xc:"cmyk(0,255,255,0)" -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc -format "%[pixel:u.p{0,0}]\n" info:
srgb(93%,11%,14%)

      

+1


source


Is there anything you can tweak in the format to provide more significant numbers in srgb (X%, X%, X%)

Probably due to different versions of IM. IM 7.0.7.8 shows srgb (93.0648%, 11.1254%, 14.1741%). IM 6.9.9.20 shows integers. I tried adding -precision 4 to the IM 6 command line but still get integers. To get more precision, you need to parse the txt: output format.

For example, indiscriminately:

convert xc:"cmyk(0,255,255,0)" -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (60990,7291,9289)  #EE3E1C7B2449  srgb(93%,11%,14%)

      

So you need to parse 16-bit values ​​(for IM Q16) in parentheses, namely (60990,7291,9289)



vals=`convert xc:"cmyk(0,255,255,0)" \
-profile /Users/fred/images/profiles/USWebCoatedSWOP.icc \
-profile /Users/fred/images/profiles/sRGB.icc txt: |\
tail -n +2 | sed -n 's/^.*[(]\(.*\)[)][ ]*\#.*$/\1/p'`
red=`echo $vals | cut -d, -f1`
green=`echo $vals | cut -d, -f2`
blue=`echo $vals | cut -d, -f3`
red=`convert -precision 4 xc: -format "%[fx:100*$red/quantumrange]" info:`
green=`convert -precision 4 xc: -format "%[fx:100*$green/quantumrange]" info:`
blue=`convert -precision 4 xc: -format "%[fx:100*$blue/quantumrange]" info:`
color="srgb($red%,$green%,$blue%)"
echo "$color"
srgb(93.06%,11.13%,14.17%)

      

Adjust the -value for the number of significant digits you want.

NOTE. In IM 7, -precision works.

magick xc:"cmyk(0,255,255,0)" -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc -format "%[pixel:u.p{0,0}]\n" info:
srgb(93.0648%,11.1254%,14.1741%)

magick -precision 4 xc:"cmyk(0,255,255,0)" -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc -format "%[pixel:u.p{0,0}]\n" info:
srgb(93.06%,11.13%,14.17%)

magick -precision 2 xc:"cmyk(0,255,255,0)" -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc -format "%[pixel:u.p{0,0}]\n" info:
srgb(93%,11%,14%)

      

+1


source







All Articles