Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Take a look at Fold[] – Dr. belisarius Feb 25 '14 at 14:22
@belisarius I've done the following. But I have no idea on why it's not working. – Voyska Feb 25 '14 at 14:36
up vote 2 down vote accepted

Try something like:

   Fold[ImageMultiply[#1, #2]&, #[[1]], Rest@##] &@ (Import/@ FileNames["*.gif"])
share|improve this answer
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. – Voyska Feb 25 '14 at 14:56
@PristineKavalostka Err ..not much to say.It's a basic recursive form Fold[f,x,{a,b}] -> f[f[x,a],b] – Dr. belisarius Feb 25 '14 at 14:59

Your Answer


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.