Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can Import data from excel and create a gray-scale image using

Image[data, "Real"]

But I want to change from grayscale and as an example use red as the color

share|improve this question
Look the option ColorSpace under Image in the documentation. – Sektor Feb 20 '14 at 19:37
@Sektor Gray is gray, regardless of color space. – C. E. Feb 20 '14 at 19:48
@Pickett Oh, I missed the grayscale part :D – Sektor Feb 20 '14 at 21:23
Please add some actual data. – Yves Klett Feb 21 '14 at 7:10
up vote 5 down vote accepted

Here's one way:

data = RandomReal[{0, 1}, {100, 100}];
ColorCombine[{Image[data], Image[0 data], Image[0 data]}]

enter image description here

This creates an RGB image which has the data as the Red channel, and all zeros in the Green and Blue channels. By weighting them differently you can get any color you wish. For instance, you can get yellow:

ColorCombine[{Image[data], Image[data], Image[0 data]}]

enter image description here

share|improve this answer

For this purpose you can use the function Colorize which is sufficient even for fancy coloring. Let's make some examples with a B&W photo

img = Import[""]


If you simply want to use the gray channel as one or more color channels you use

Colorize[img, ColorFunction -> Function[gray, RGBColor[0, gray, gray]]]

Mathematica graphics

The same works of course with other color functions

Colorize[img, ColorFunction -> Function[gray, Hue[0.6, 1 - gray, gray]]]

Mathematica graphics

With the built-in color schemes of Mathematica you can get more fancy looks and the usage is even simpler

Colorize[img, ColorFunction -> "AvocadoColors"]

Mathematica graphics

Or you mix everything together

Colorize[img, ColorFunction -> 
  Function[gray, RGBColor @@ (gray*List @@ ColorData["BrightBands", gray])]]

Mathematica graphics

share|improve this answer

If you have a worksheet like this one:

Mathematica graphics

You could do:

id = Import["C:\\test.xlsx"];
ColorCombine[Image /@ ({#, # 0, # 0} &@id[[1]])]

Mathematica graphics

Note for wicked users:Yes, I always store my photos in Excel.

share|improve this answer

There are many functions that generate RGBColor[r,g,b] and these can often be helpful even for purposes such as this. Blend figures out the correct red, green, and blue components and then I extract them using a rule, putting them into the required format {r,g,b}.

Another thing worth noting is that I use an anonymous function that I give that property Listable so that it is applied on all elements of the matrix automatically.

col = Function[x, Blend[{Red, Black}, x] /. RGBColor[r_, g_, b_] :> {r, g, b}, Listable];
share|improve this answer

Your Answer


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.