0

I have a set of images in a folder which their names are: 2 days.bmp 3 days.bmp ..... 28 days.bmp. Also, I have a folder with the background images exactly with the same names. I want to use the calculator plus and divide each image to its relevant background. I want to save time and do that at the same time instead of doing it for each image one by one. Is there any idea how can I do that? I have written a macro but it didn't work for me.

macro "Batch calculate images [1]" {

LocationOfFiles = getDirectory("Select Folder");

LocationOfbackgrounds = getDirectory("Select Folder of backgrounds");

LocationOfSave = getDirectory("Select Save Location");


setBatchMode(true);

FileList = getFileList(LocationOfFiles);

NumberOfFiles = FileList.length;

for (i=0; i<NumberOfFiles; i+=1) {

FileName = FileList[i];

pathtofile1 = LocationOfFiles+FileName;

open(pathtofile1);

name1 = getTitle();

pathtofile2 = LocationOfbackgrounds+FileName;

open(pathtofile2);

name2 = getTitle();

run("Calculator Plus", "i1="+name1+" i2="+name2+" operation=[Divide: i2 = (i1/i2) x k1 + k2] k1=255 k2=0 create");

selectWindow("Result");

SaveName = replace(name, ".bmp", "_backgroud subtracted.jpg");

saveAs("BMP", LocationOfSave+SaveName);

selectWindow(BackgroundImage);

close("\\Others");
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    I recommend to ask this question on the image.sc forum, as it is very specific to ImageJ and its macro language: https://forum.image.sc/ – Jan Eglinger Nov 20 '18 at 08:14
  • 1
    The question is ImageJ-specific and likely a bit off-topic here. In addition, that same question was asked [on the forum](https://forum.image.sc/t/macro-for-multiple-images-analysis-in-the-calculator-plus/20992?u=imagejan) and [the mailing list](http://imagej.1557.x6.nabble.com/How-to-write-a-macro-for-multiple-images-analysis-in-the-calculator-plus-tp5021469.html) and received replies there already, so let's close it here. – Jan Eglinger Nov 20 '18 at 12:11

0 Answers0