How can i calculate cmyk values from rgb in matlab?

87 次查看(过去 30 天)
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 ?rgb.png
  2 个评论
Rik
Rik 2020-1-14
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
Stephen23 2020-1-16
@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).

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2020-1-10
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);
See matlab's documentation on profile-based colour conversion.
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 个评论
ahmad Al sarairah
ahmad Al sarairah 2020-1-16
Thank you , but i have another questiion about this toic :
How can i use "imwrite" function to wtite the converted data to a file?. because i used this function but I got this error :
Error using writejpg (line 46)
Data with 4 components not supported for JPEG files.
Guillaume
Guillaume 2020-1-16
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.

请先登录,再进行评论。

更多回答(1 个)

ahmad Al sarairah
ahmad Al sarairah 2020-1-19
How can i solve this problem? :
Cannot display summaries of variables with more than 524288 elements.
  1 个评论
Guillaume
Guillaume 2020-1-19
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by