Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
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.

share|improve this question
2  
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
1  
@RHall, please fix your code above, you are clearly missing a set of curly braces. –  chuy Jun 18 '13 at 21:18
add comment

2 Answers

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

rgb colors

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

rgbValues = {##} & @@@ rgb
share|improve this answer
    
+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
3  
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
show 2 more comments

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} ... *)
share|improve this answer
    
+1 for a Cleaner solution! –  R Hall Jun 19 '13 at 20:58
    
ColorConvert[#, RGBColor, ColorSpace -> CMYKColor] & /@ cmyk also works. –  J. M. Jun 20 '13 at 0:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.