# How can Mathematica convert CMYK values to RGB or HSB?

cmyk = {{0., 0.05, 0., 0.}, {0., 0.1, 0., 0.2}, {0.1, 0.2, 0.1, 0.1}, {0.1, 0.2, 0.1, 0.},
{0., 0.1, 0., 0.1}, {0., 0.15, 0., 0.}, {0., 0.07, 0., 0.07}, {0., 0.07, 0., 0.},
{0., 0.02, 0., 0.}, {0., 0.1, 0., 0.}, {0., 0.3, 0., 0.}, {0.2, 0.3, 0.2, 0.},
{0.1, 0.3, 0.1, 0.}, {0., 0.25, 0., 0.}, {0., 0.2, 0., 0.1}, {0., 0.2, 0., 0.},
{0., 0.2, 0., 0.2}, {0.1, 0.4, 0.1, 0.}, {0.3, 0.4, 0.3, 0.}, {0.1, 0.4, 0.1, 0.1},
{0.2, 0.4, 0.2, 0.}, {0.2, 0.4, 0.2, 0.1}, {0.2, 0.4, 0.2, 0.2},
{0.4, 0.55, 0.4, 0.}, {0., 0.2, 0., 0.4}};

I have tried quite a few things, but it seems there is an assumption the data is RGB even if there are 4 values in the array.

-
Have you tried the ColorConvert function? – KAI Jun 18 '13 at 20:30
4 value List may leads to RGBA color instead of RGB, where the 4th number is used for the alpha channel. – Silvia Jun 18 '13 at 21:02
@KAI Yes Certainly and the result is still a 4d array – R Hall Jun 18 '13 at 21:13
@Silvia That's what I ran into also. – R Hall Jun 18 '13 at 21:14
@RHall, please fix your code above, you are clearly missing a set of curly braces. – chuy Jun 18 '13 at 21:18

rgb = ColorConvert[#, "CMYK" -> "RGB"] & /@ CMYKColor @@@ cmyk
ImageAssemble[{Graphics[#, ImageSize -> 20] & /@
Partition[Riffle[rgb, Rectangle[], {2, -1, 2}], 2]}]

Edit: to get raw values, use this additional line of code:

rgbValues = {##} & @@@ rgb
-
+1 Nice solution, but produces an error on larger arrays. I just want the RGB values not a colored result. – R Hall Jun 18 '13 at 21:15
{{RGBColor[0., 0., 0.], RGBColor[0., 0., 0.]}} the result produces this type of return, I need {{0., 0., 0.},{0., 0., 0.}} this type. – R Hall Jun 18 '13 at 21:24
See edit, added this feature. – shrx Jun 18 '13 at 21:28
rgbValues = List @@@ rgb would be sufficient. (+1) – Silvia Jun 18 '13 at 21:39
@R Hall how large is your array that causes problems, and what does the error message say exactly? – shrx Jun 18 '13 at 21:42

You can also use the ColorSpace option of ColorConvert to tell it how to interpret the input data. This allows you to go directly from raw data to raw data, without the CMYKColor and RGBColor heads:

rgb = ColorConvert[#, "RGB", ColorSpace -> "CMYK"] & /@ cmyk

(* {{1., 0.95, 1.}, {0.8, 0.72, 0.8}, {0.81, 0.72, 0.81}, {0.9, 0.8, 0.9} ... *)
-
+1 for a Cleaner solution! – R Hall Jun 19 '13 at 20:58
ColorConvert[#, "CMYK" -> "RGB"] & /@ cmyk also works. – J. M. May 21 at 16:32