A problem with writing a macro code for using calculator plus pluging, divide operation in image J

imagej1
imagej
plugin
batch-processing
macro
image-calculator
calculator-plus

#1

Hello

I wrote a code to divide some images that I have to background images with the same name as my original images. I have two problems with the code below:

  1. When I use this code, my outputs are exactly the same name of my original files, not that one I want and have written in this code. ( I want to have “_ subtracted” in the continuation of the name)

  2. When I divide my images one by one with calculator plus ( not macro) I get different results ( I mean the gray values I get from using macro and using calculator plus directly are different). What is the problem? my calculations are very sensitive to the gray value change.

macro "Batch calculate images [1]" {
LocationOfFiles = getDirectory("Select Folder");
LocationOfbackgrounds = getDirectory("Select Folder of backgrounds");
LocationOfSave = getDirectory("Select Save Location");
setBatchMode(true);
FileList1 = getFileList(LocationOfFiles);
FileList2 = getFileList(LocationOfbackgrounds);
NumberOfFiles = FileList2.length;
for (i=0; i<NumberOfFiles; i+=1) {
  FileName1 = FileList1[i];
  pathtofile1 = LocationOfFiles+FileName1;
  open(pathtofile1);
  name1 = getTitle();
  FileName2 = FileList2[i];
  pathtofile2 = LocationOfbackgrounds+FileName2;
  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(name1,"tiff","-subtracted.tiff");
  saveAs(".bmp", LocationOfSave+SaveName);
}
close("\\Others");
}

#2

Maybe you are aware of this, but just in case: division with the image_calculator_plus and the image_calculator are not the same thing.
Have a look at the source code of IJ and the image_calculator_plus.


#3

But I used calculator plus for both my macro and manual analysis and got different results


#4

Sorry I misunderstood your post.
Can you post an example with a shorter macro that shows the difference?
Are you sure that the FileList1 and FileList2 return the correct pairs of images?
Maybe it would be safer to get the first image list and then select the divisor image based on the name of the numerator image.