Reputation: 131
this is my first time asking question in stackoverflow. I tried hard not to make any guideline violations, but let me know if there is any—please understand since it is my first time.
I have a code in Mathematica, and I think it is REALLY slow.
I have a stack of images—couple hundreds, and I was creating a simple algorithm in Mathematica to combine images into a single image by averaging pixel data across the entire stack.
For example, assume that I have a pixel at 520 x 23, and I want to get all the number(data) from every single images in the stack and average that table. I want to repeat this process for every single pixel in my image. Then, I will be able to reconstruct the data into an image using Image[]. For the testing, I used 1024 by 1024 image, but I want to use 8000 by 8000 eventually.
Here is my code:
idlist = Map[ImageData, ilist];
Table[Table[Map[Mean,Transpose[Table[idlist[[a,b,c]],{a,1,Length[idlist]}]]],{b,1,1024}], {c, 1, 1024}]
I found out that my nested Table was faster than using a single Table for some weird reasons.
1.How should I optimize this? 2.Is there a benefit using any parallel computing for this specific implementation?
Upvotes: 1
Views: 701
Reputation: 61046
I'm not sure if I'm following your coding, but to get the mean pixel value for a bunch of images, you could simply do the following (it's fast):
imDim = 100;
n = 80;(*number of images*)
(*generate random image list*)
ilist = Array[RandomImage[1, {imDim, imDim}, ColorSpace -> "RGB"] &, n];
(*take mean*)
Image@Mean[ImageData /@ ilist]
For a large collection of random images it should converge to homogeneous gray (RGB[.5,.5,.5]). Let's test it:
imDim = 3;
n = 2000;(*number of images*)
(*generate random image list*)
ilist = Array[RandomImage[1, {imDim, imDim}, ColorSpace -> "RGB"] &, n];
(*take mean*)
Image@Mean[ImageData /@ ilist]
Upvotes: 1