How can i calculate cmyk values from rgb in matlab?

112 vues (au cours des 30 derniers jours)
ahmad Al sarairah
ahmad Al sarairah le 8 Jan 2020
Commenté : Guillaume le 19 Jan 2020
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 commentaires
Rik
Rik le 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
Stephen23 le 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).

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 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);
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 commentaires
ahmad Al sarairah
ahmad Al sarairah le 16 Jan 2020
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 le 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.

Connectez-vous pour commenter.

Plus de réponses (1)

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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by