Login  Register

How to write a macro for multiple images analysis in the calculator plus?

Posted by behravan1987 on Nov 20, 2018; 12:02am
URL: http://imagej.273.s1.nabble.com/How-to-write-a-macro-for-multiple-images-analysis-in-the-calculator-plus-tp5021469.html

Hello everyone

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.
Thanks.



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");



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html