I'm trying to do the following:

l = FileNames[];
s[x_] := ToString[l[[x]]]
t = Table[s[x], {x, 1, Length[l]}];
i[x_] := Import[t[[x]]]
m[x_] := ImageMultiply[i[x], i[x + 1]]

This is supposed to take two images of one folder and multiply them. But I want to take two images and multiply them, then I want to take the next two, multiply them and multiply to the last multiplied images and proceed like this for all the images in the folder.

I already have a table with all the file locations, the problem is that ImageMultiply[] doesn't take lists as inputs. I wasn't able to do something like:


Which would solve the problem, but the input of this function is:


And not:

ImageMultiply[{image1,image2, ...}]

Perhaps there is some way of drop all the elements out of the list into that function, I don't know about it. I've also looked some functions that look extremelly similar to what I'm trying to do, I guess that there's some way to use NestList[] or Nest[] to do it, but I've tried a few experiments and it resulted in hazard...$^1$

$1$ - I don't remember precisely which arguments (then I chose arbitrary ones) I used in that function, but it really froze my computer.


Try something like:

   Fold[ImageMultiply[#1, #2]&, #[[1]], Rest@##] &@ (Import/@ FileNames["*.gif"])
  • $\begingroup$ I'll do it, thanks. But could you explain a little further what's happening in there? It could be some references, I've looked the Mathematica documentation on this and I didn't get it. $\endgroup$
    – Red Banana
    Feb 25 '14 at 14:56
  • $\begingroup$ @PristineKavalostka Err ..not much to say.It's a basic recursive form Fold[f,x,{a,b}] -> f[f[x,a],b] $\endgroup$ Feb 25 '14 at 14:59

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .