Re: Need faster way to combine arrays
- To: mathgroup at smc.vnet.net
- Subject: [mg36064] Re: [mg36045] Need faster way to combine arrays
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Thu, 15 Aug 2002 02:36:15 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On Wednesday, August 14, 2002, at 05:35 AM, Kevin Gross wrote:
> Hello all,
>
> I've been using Mathematica for a while, but only recently for image
> processing. Suppose I have the following 2D intensity arrays:
>
> r={{a1,b1},{c1,d1}};
> g={{a2,b2},{c2,d2}};
> b={{a3,b3},{c3,d3}};
>
> Now I'd like to combine them to produce a color image.
>
> color=Table[{r[[i,j]],g[[i,j]],b[[i,j]]},{i,2},{j,2}]
>
> This returns
>
> {{{a1, a2, a3}, {b1, b2, b3}}, {{c1, c2, c3}, {d1, d2, d3}}}
>
> which can be viewed as a color image with
>
> Graphics[Raster[color,ColorFunction->RGBColor]]//Show
>
> When the 2D arrays are large, combining them to form the color tensor as
> above is very time consuming. Surely there is a more efficient, clever
> way to combine them than my use of Table, right?
>
> Many thanks,
>
> Kevin Gross
>
> PS Any comments pro/con from users of the Digital Image Processing
> package are also welcome.
>
I'm not a user of the Digital Image Processing package but I got the
following results combining 3 1000x1000 arrays on a 1GHz Mac with
version 4.2:
In[5]:=
n=1000;
{r,g,b}=Table[Table[Random[Integer],{n},{n}],{3}];
In[3]:=
Timing[Table[{r[[i,j]],g[[i,j]],b[[i,j]]},{i,Length[r]},{j,Length[r
[[1]]]}];]
Timing[Partition[Transpose[{Flatten[r],Flatten[g],Flatten[b]}],n];]
Out[3]=
{3.11 Second,Null}
Out[4]=
{0.2 Second,Null}
With n=10000 I run out of memory however.
Regards,
Ssezi