Martin Møller Skarbiniks Pedersen
2020-Nov-30 20:15 UTC
[R] RGB -> CYMK, with consistent colors
On Sun, 29 Nov 2020 at 20:55, Derek M Jones <derek at knosof.co.uk> wrote: [...]> > library("colorspace") > > two_c=rainbow(2) > x=runif(20) > y=runif(20) > plot(x, y, col=two_c[2]) > pdf(file="cmyk.pdf", colormodel="cmyk") > plot(x, y, col=two_c[2]) > dev.off()rainbow(2) gives two RGB-colours: #FF0000 (=pure red) and #00FFFF (=pure cyan). So it should be no problem to match two_c[2] perfect in CMYK-colourspace However after some testing. I totally agree that CMYK handling in R using pdf(..., colormodel = "cmyk") is not correct. One solution: Output in tiff or png instead and then convert to CMYK using external tools. Try this: png("plot.png") plot(runif(10), runif(10), col = ""#00FFFF") # cyan dev.off() And then convert plot.png using: https://www.online-utility.org/image/convert/to/CMYK Regards Martin [[alternative HTML version deleted]]
Martin,> However after some testing. > I totally agree that CMYK handling in R using pdf(..., colormodel = "cmyk") > is not correct.I thought the issue may be OS specific, but I get similar behavior on a Mac. I have discovered the Cyan tool: http://cyan.fxarena.net/ and will try it out. As various people have pointed out, RGB -> CMYK conversion is never going to be perfect. It just so happens that my book contains many plots that use red and cyan, and a good conversion to cyan is most of what I am after. > One solution: > Output in tiff or png instead and then convert to CMYK using external tools. There are 600+ figures. There are png versions here: http://knosof.co.uk/ESEUR/figures/index.html
Martin,> However after some testing. > I totally agree that CMYK handling in R using pdf(..., colormodel = "cmyk") > is not correct.Looking at the source code of the function PostScriptSetCol in file src/librarygrDevices/src/devPS.c the conversion to CMYK looks correct. Looking at the generated pdf (qpdf: https://github.com/qpdf/qpdf is needed to uncompress the pdf) the numeric color values look correct, although the pdf contents don't exactly match those generated by PostScriptSetCol It is possible the problem is in the conversion that occurs when displaying/printing a pdf.