Performing Image Calculator on entire folder



I would like to perform image calculations on an entire folder. I have a folder with .TIFF pictures all named differently. I would like to do Process > Image Calculator > Multiply with each pairs of 2.

For example:
(Image 1 x Image 2) --> Result --> Save as “Img1”
(Image 3 x Image 4) --> Result --> Save as “Img2”
(Image 5 x Image 6) --> Result --> Save as “Img3”

And so on… Can anyone guide me to the right path? How can I achieve this.


This is what I have so far:

   dir1 = getDirectory("Choose Source Directory ");

list = getFileList(dir1);
for (i=0; i<list.length; i++) {
titleOne = getTitle(dir1+list[i]);
titleTwo = getTitle(dir1+list[i+1]);


Would this work? I am also not sure how to save the image once this is done… Any help would be appreciated!


Dear @whysa,

Not as you have described before. First, you have to open the two images (and getTitle() always returns the title of the currently active image):

titleOne = getTitle();
titleTwo = getTitle();

Also, if you want Image1 * Image2 and Image3 * Image4 etc, you have to adapt the counting variable in your for loop. With i++ you are increasing it by 1 in every iteration. You will, however, have to increase it by 2 to get your expected behavior:

for (i=1; i<=list.length; i=i+2) {
    // Your code

As to saving:

rename("Img"+i) // Rename the image after multiplication
saveAs("tiff", dir1+"Img"+i+".tif"); // Save with the new name