3
$\begingroup$

I have a list of LABColors: {{l1,a1,b1},{l2,a2,b2}..{ln,an,bn}} I want to convert it to a list of RGBColors of same form: {{r1,g1,b1}, {r2,g2,b2}, .. {rn,gn,bn}}

I have been trying for a few hours but I keep running into snags ..

for example: c1 = LABColor[l1,a1,b1] -> I get a color swatch

ColorConvert[c1, "RGB"] -> I get a good transform, but it is a color swatch

ColorConvert[c1, "RGB"] // InputForm -> I get RGBColor[r1,g1,b1]

and I am stuck here.

I need the result to be in list form {{r1, g1, b1},...}

Thanks for any suggestions, pointers :)

$\endgroup$
6
  • $\begingroup$ In Mathematica an RGB color is represented as RBGColor[r, b, g]. You want to replace RBGColor with List: rgbcolors /. RGBColor -> List. Yes/no? $\endgroup$
    – Michael E2
    Commented Feb 7, 2022 at 1:05
  • $\begingroup$ My list of numerical colors are in LAB space, and I want to convert to a list of RGB numerical values. $\endgroup$ Commented Feb 7, 2022 at 1:22
  • $\begingroup$ You said, "I get RGBColor[r1,g1,b1]" and I showed how to take it another step...but I have another way...in a sec $\endgroup$
    – Michael E2
    Commented Feb 7, 2022 at 1:24
  • $\begingroup$ I got it! thanks, that worked! :) $\endgroup$ Commented Feb 7, 2022 at 1:34
  • $\begingroup$ I couldn't find RBGColor... are you sure it is RBGColor? The documentation says RGBColor, (RGB, not RBG).. just double checking $\endgroup$ Commented Feb 7, 2022 at 3:37

1 Answer 1

5
$\begingroup$

Here is some LAB color data in the form of an $n\times3$ array of real numbers:

labdata = 
  Diagonal[
   ImageData@
    ColorConvert[ExampleData[{"TestImage", "Mandrill"}], "LAB"]];

Here is the conversion to an RGB array:

rgb1 = First@
   ImageData@
    ColorConvert[Image[{labdata}, ColorSpace -> "LAB"], "RGB"];

Another (slower) way:

rgb2 = ColorConvert[labdata, "LAB" -> "RGB"] /. RGBColor -> List
$\endgroup$
1
  • $\begingroup$ Thanks so much! the (slower) is more to my skill level right now, but perfect for me. Thanks again $\endgroup$ Commented Feb 7, 2022 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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