How can i calculate cmyk values from rgb in matlab?
81 views (last 30 days)
Show older comments
I have an image with .jpg format , and i got the values of (R,G,B,C,M,Y,K) for all pixels . but I want to know how to calculate cmyk values as calculated, for example :
the values of first pixel(0,0) were as follows :
R=22
G=32
B=42
C=167
M=130
Y=95
K=199
So ,what is the relationship between 22, and 167 or 32 and 130 ?
2 Comments
Rik
on 14 Jan 2020
Slightly off-topic: you really shouldn't put your own files in the installation directory of matlab. Use another folder on your computer.
I would also strongly recommend not using Windows 7 anymore, unless you are working on a computer from an organization that has an agreement with Microsoft that ensures continuing updates.
Stephen23
on 16 Jan 2020
@RIk: Well spotted!
@ahmad Al sarairah: as Rik wrote, do NOT save your personal files in the installation directory of any application. With MATLAB the simplest is to use the default Startup directory (which is under your <user> directory).
Accepted Answer
Guillaume
on 10 Jan 2020
People who use simple formulae like the one in the other answer are people who do not understand CMYK.
Typically, if you want to convert from RGB to CMYK it's because you want to send some image to a print shop. Once printed you want the image to look exactly (in terms of colour) as your original image. Unfortunately, the look is going to depend on the actual printer. One printer will generate slightly different colour than another for the input. Therefore, people who manage these things have created what is called ICC profiles, which is basically a file that tells you exactly what the colours are going to look like. If you don't take these into account then the red in your original RGB image may look pink with one printer and orange on another.
In order to convert RGB to CMYK you need the ICC profile of the RGB device that has been used to generate the image (your monitor) and the ICC profile of the printer (which the print shop will give you). Once you've got these, it is trivial to transform RGB to CMYK in matlab with the applycform function:
inprof = iccread(yourmonitoriccprofile);
outprof = iccread(theprinterprofile);
rgb_to_cmyk = makecform('icc', inprof, outprof);
cmyk_image = applycform(rgb_image, rgb_to_cmyk);
Note that converting RGB to CMYK without taking profile into account (eg with naive formulae) is a complete waste of time. You may as well give the RGB file directly to the print shop which will do a better job of printing it correctly.
20 Comments
Guillaume
on 16 Jan 2020
You're still persisting with this idea of CMYK, which is not going to work!
While the JPEG format does support CMYK, not many software implement that support. In particular, matlab does not support it. In matlab, as far as I know, the only format that supports CMYK is tiff.
Again, you're wasting your time.
More Answers (1)
ahmad Al sarairah
on 19 Jan 2020
1 Comment
Guillaume
on 19 Jan 2020
This is unrelated to your original question (and certainly not an answer to it) so you should probably start a new question.
Why is it a problem? Yes, the variable editor won't display matrices with that many elements. If it's an image you're trying to look at, imshow or imtool would be a better visualisation tool than the variable editor.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!