Page 1 of 1
RGB to CMYK conversion accuracy
Posted: 2012-04-04T03:42:42-07:00
by alan
Hi, we are using this command line in a PHP script to automate the conversion of RGB image files to CMYK:
exec ("convert $infolder/$image +profile '*' -profile /path/to/sRGB_v4_ICC_preferences.icc -colorspace CMYK -profile /path/to/USWebCoatedSWOP.icc $outfolder/$outimage");
It works, but the conversion is not a close match. I have attached the original RGB file, the IM conversion and a photoshop conversion for comparison. The photoshop is acceptably close - the IM version is a long way off. Is it something we are doing wrong? or is it a shortcoming in the IM conversion? We have noted quite a bit of discussion around this in the forums.
Our PHP install is running Version: ImageMagick 6.5.7-8
Here is a link to our sample test files:
http://www.dunnsprophoto.co.uk/imagetest/
Thanks for any quidance
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-04T10:36:30-07:00
by fmw42
exec ("convert $infolder/$image +profile '*' -profile /path/to/sRGB_v4_ICC_preferences.icc -colorspace CMYK -profile /path/to/USWebCoatedSWOP.icc $outfolder/$outimage");
I am no expert on this, but why do you include both -colorspace CMYK and the USWebCoatedSWOP.icc profile.
Try removing -colorspace CMYK
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-04T11:01:06-07:00
by magick
Also ensure you have LCMS support built into your release of ImageMagick. Type
Ensure LCMS is associated with the DELEGATES tag.
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-05T05:10:33-07:00
by alan
Thanks for the input. We have confirmed LCMS is associated correctly.
We agree about the doubt about needing -colorspace CMYK, but leaving it out seems to produce (according to the header)an RGB image with a CMYK profile attached. When you try to open this in photoshop it first says 'attached colour profile is invalid' and then proceeds to open it as an untagged RGB file! Putting in -colorspace CMYK certainly appears to change the image into a four colour channel CMYK image. It just doesn't look so good!
alan
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-05T13:18:53-07:00
by Rodrigo
Hi,
I´m having the same problem here.
I need generate a hight quality final image to print.
In my application (PHP) I´m creating a RGB 72dpi JPEG image and then I´m trying transform to CMYK 300dpi JPEG.
But the color and the quality of final image created is not good.
When I try use the PHP class Imagick, the results are completly different. So, I´m using now the exec() function to run the commands. Like in the previous posts of alan.
Please check this link where I put 3 examples (with the codes):
http://rodrigopandini.com/test/index.php
After various tests, the example 3 is the most reasonable to use, but the quality of the image still really bad.
So, my problem now is improve the final image quality.
Some suggestions?
ps: Other thing that I noticed is that colors of the cmyk are too different when open in browser (Chrome) to photo viewer of the Windows.
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-05T13:23:02-07:00
by fmw42
CMYK images do not display correctly on some browsers. Check your image with other viewers.
This works for me.
convert rgb01.jpeg -profile Profiles/sRGB.icc -profile Profiles/USWebCoatedSWOP.icc cmyk01.jpg
However, when displayed in my browser it looks wrong. But when displayed in another viewer, it looks fine.
It is strange, but this works by adding -negate so that it looks right in my browser.
convert rgb01.jpeg -profile Profiles/sRGB.icc -profile Profiles/USWebCoatedSWOP.icc -negate cmyk01.jpg
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-05T13:26:31-07:00
by Rodrigo
OK,
But and about the quality?
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-05T13:32:55-07:00
by fmw42
The quality looks fine to me, though slightly darker. You are going to lose some quality when you convert jpg to jpg as it is a lossy format. So the output is slightly less sharp.
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-05T13:47:42-07:00
by Rodrigo
ok, I undestand now that when convert from jpeg to jpeg the quality will decrease. But, I´m trying convert from a png to a cmyk jpeg image and this not working. The final image still in rgb colorspace. Some other options?
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-05T15:19:35-07:00
by fmw42
Post a link to your PNG input image. All your posted input images are jpg.
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-09T07:48:04-07:00
by Rodrigo
Hi,
Now I put the png image at the example. It´s the first image. Check the link again.
Thank you.
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-09T11:52:45-07:00
by fmw42
convert rgb.png -alpha off -profile Profiles/sRGB.icc -profile Profiles/USWebCoatedSWOP.icc cmyk.jpg
the above gives a result which does not display correctly in my browser, but looks fine in other viewers, except the green is slightly darker than in your original
convert rgb.png -alpha off -profile Profiles/sRGB.icc -profile Profiles/USWebCoatedSWOP.icc -negate cmyk_neg.jpg
the above looks reasonable in my browser, but again the green is slightly darker.
Again, not all browsers or views can display cmyk properly.
As to the slightly darker green, I do not know how to make that better. Perhaps try other RGB/sRGB profiles and other cmyk profiles.
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-10T11:03:30-07:00
by Rodrigo
Thank you for reply.
I used your first command and the result looks good.
Here the green also goes slightly darker than the original image, but it OK since it´s the same result that I got when I use Photoshop.
As I said before my problem was more about the quality of the final image.
Before I was not able to convert from rgb.png -> cmyk.jpg directly.
I was converting rgb.png -> rgb.jpg -> cmyk.png.
So, now, with your command, I can convert rgb.png -> cmyk.jpg directly and the quality still good.
In time,
I my code, the front-side (canvas) will send the base64 encoded string of the image to the server-side to create the image in PHP. I´m using imagecreatefromstring() function from the GD lib of PHP to create this rgb.png image.
http://www.php.net/manual/en/function.i ... string.php
My ideia now it try to use the correspondent function in ImageMagick to create directly the cmyk.jpg , instead of create the rgb.png and next convert to cmyk.jpg.
I was searching something like this function in ImageMagick and I found "inline" format.
"The inline image look similar to inline:data:;base64,/9j/4AAQSk...knrn//2Q==. If the inline image exceeds 5000 characters, it must be referenced from a file (e.g. inline:inline.txt)."
But I dont found any good example of this.
A little help here?
Thank you.
Re: RGB to CMYK conversion accuracy
Posted: 2012-04-10T21:20:27-07:00
by anthony
fmw42 wrote:It is strange, but this works by adding -negate so that it looks right in my browser.
convert rgb01.jpeg -profile Profiles/sRGB.icc -profile Profiles/USWebCoatedSWOP.icc -negate cmyk01.jpg
a
-negate of a RGB image produces a CMY colorspace image, it is actually the definition of what a CMY image is. However that should be linear RGB! I do not believe CMY (or CMYK) images use non-linear values like sRGB images do.
But this is only a to CMY image, not CMYK image. CMYK pulls out the minimum (command to all) CMY value to use as the 'blacK' channel, then subtracts that from the other three (One C, M or Y value in a CMYK is always zero)! this is also what a conversion from any colorspace to CMYK does. as long at Im does indeed know exactly what colorspace the image is in.
Other than that I really can not help much here as I have have very little experience with color profiles. Their may be some bugs left over from the RGB/sRGB default colorspace swap Imagemagick made recently, such as to what a second
-profile will actually convert to/from. I think it actually just deals with the image values AS IS, so it may be that you need to use profiles to first convert the image to linear-RGB or sRGB colorspaces, then use
-set colorspace to tell IM what it is (without further changing the color values), before you can actually process the image in any way.
I do know that a if an image does not have a profile it should be thought of as sRGB, and that is what Imagemagick now does. So this should do the task (assuming the original does not have a profile, the
+profile makes sure of it but it should not be nessary)
Code: Select all
convert rgb01.jpeg +profile -set colorspace sRGB -colorspace CMYK -profile Profiles/USWebCoatedSWOP.icc -negate cmyk01.jpg
But this should have worked too!
Code: Select all
convert rgb01.jpeg +profile -profile Profiles/sRGB.icc -profile Profiles/USWebCoatedSWOP.icc cmyk01.jpg
NOTE: the above may still not work if OTHER profiles are present in the image! See Im examples Profiles for some I have noted...
http://www.imagemagick.org/Usage/formats/#profiles
There is colorspace settings in other profiles and which ones photoshop uses, and which web browsers use may not be the same. Anyone with information about this would be most welcome!