0
$\begingroup$

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.

$\endgroup$
2
  • 1
    $\begingroup$ Take a look at Fold[] $\endgroup$ Commented Feb 25, 2014 at 14:22
  • $\begingroup$ @belisarius I've done the following. But I have no idea on why it's not working. $\endgroup$ Commented Feb 25, 2014 at 14:36

1 Answer 1

2
$\begingroup$

Try something like:

 SetDirectory["whatever"]; Fold[ImageMultiply[#1, #2]&, #[[1]], Rest@##] &@ (Import/@ FileNames["*.gif"]) 
$\endgroup$
2
  • $\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$ Commented Feb 25, 2014 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$ Commented Feb 25, 2014 at 14:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.