MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to combine 3 grayscale images into one RGB color image ?


I don't understand mixing colors so this probably isn't right, but it may get you started.

Needs["Graphics`"];

nr=5;nc=4;
r=Table[Random[],{nr},{nc}];
g=Table[Random[],{nr},{nc}];
b=Table[Random[],{nr},{nc}];

Clear[clr];
clr[c_Integer/;0<c<=nr*nc]:=Module[{
        m=Floor[(c-1)/nc]+1,
        n=Mod[c-1,nc]+1},
      RGBColor[r[[m,n]],g[[m,n]], b[[m,n]]]];

DisplayTogetherArray[{{
        DensityGraphics[r],
        DensityGraphics[r,
          ColorFunction->(RGBColor[#, 0, 0]&),
          Mesh->False]},
      {DensityGraphics[g],
        DensityGraphics[g,
          ColorFunction->(RGBColor[0, #, 0]&),
          Mesh->False]},
      {DensityGraphics[b],
        DensityGraphics[b,
          ColorFunction->(RGBColor[0, 0, #]&),
          Mesh->False]},
      {DensityGraphics[(r+g+b)/3],
        DensityGraphics[Table[nc*(r-1)+c,{r,nr},{c,nc}],
          ColorFunction->(clr[#]&),
          ColorFunctionScaling->False,
          Mesh->False]}},
    ImageSize->300];


Bob Hanlon

---- mario.ivanov at risoe.dk wrote: 
> How to combine 3 grayscale images into one RGB color image ?
> 
> I have  3  "DensityGraphics" pictures and I want to combine them in
> such a way that the one represents the Red, the others - green and blue
> colors correspondingly.
> This procedure is called "merge channels" in Photoshop.
> 
> It must be quite easy to solve that even without external packages, but
> I am not experienced enough.
> 
> Thank you.
> 


  • Prev by Date: Re: Variables Within Homemade Functions
  • Next by Date: Re: Re: Animation crash
  • Previous by thread: How to combine 3 grayscale images into one RGB color image ?
  • Next by thread: plotting multidimensional arrays