Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

ImageMultiply[t]

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

ImageMultiply[image1,image2,...]

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
1  
Take a look at Fold[] –  belisarius Feb 25 at 14:22
    
@belisarius I've done the following. But I have no idea on why it's not working. –  Vladimir Putin Feb 25 at 14:36

1 Answer 1

up vote 2 down vote accepted

Try something like:

   SetDirectory["whatever"];
   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. –  Vladimir Putin Feb 25 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] –  belisarius Feb 25 at 14:59

Your Answer

 
discard

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.