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.

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 at 19:37
    
@Sektor Gray is gray, regardless of color space. –  Pickett Feb 20 at 19:48
    
@Pickett Oh, I missed the grayscale part :D –  Sektor Feb 20 at 21:23
    
Please add some actual data. –  Yves Klett Feb 21 at 7:10
add comment

4 Answers

up vote 4 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
add comment

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["http://i.stack.imgur.com/397vv.png"]

Eye

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
add comment

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
add comment

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];
Image[col@data]
share|improve this answer
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.