Posted by
meiemi2000 on
Sep 22, 2014; 4:40pm
URL: http://imagej.273.s1.nabble.com/Apply-a-recorded-marco-to-multiple-images-Help-tp5009711.html
Dear ImageJ gurus,
I am new to imageJ and would appreciate your help. I have been searching for a week and played with multiple code pieces without much success, so I think its time to ask.
I have images in RGB, where Red is for nuclear membrane, green is for channel of interest and blue is for DNA(not used in this macro). I want to use red to define the nuclear space (ROIs) and measure both red and green channels in these ROIs. Then I want to resize all ROIs to X% of the original ROIs and measure both red and green channels again. I recorded the macro and it runs fine, and it outputs four excel files.
Here is an example image.

Now, I want to apply the macro to a folder of images and have the output excel files titled with the original image file name (so I know which four files belong together). Can you help me to add the code to run this macro on multiple images? Or any pointer is highly appreciated!
Thanks a lot!
Here is the macro
//open RGB image first//
selectWindow("WT-0018.tif");
//split RGB channel//
run("Split Channels");
//slecte red channel (nuclear membrane) to defind the nuclear space, rename red channge as "red", green channel as "green"//
selectWindow("WT-0018.tif (red)");
run("Duplicate...", "title=red");
selectWindow("red");
selectWindow("WT-0018.tif (green)");
rename("green");
selectWindow("red");
run("Subtract Background...", "rolling=50");
setAutoThreshold("Default dark");
//run("Threshold...");
setAutoThreshold("Default dark");
setThreshold(21, 255);
setOption("BlackBackground", true);
run("Convert to Mask");
run("Fill Holes");
run("Convert to Mask");
run("Analyze Particles...", "size=5-500 circularity=0.70-1.00 show=Outlines add");
//measure ROIs in the red channel and save as an excel file//
selectWindow("WT-0018.tif (red)");
roiManager("Measure");
saveAs("Results", "/Users/hueimeichen/Desktop/red100.xls");
run("Close");
//measure ROIs in the green channel and save as an excel file//
selectWindow("green");
roiManager("Measure");
saveAs("Results", "/Users/hueimeichen/Desktop/green100.xls");
run("Close");
//resize all ROIs to 80% with ROI centered//
count = roiManager("count");
current = roiManager("index");
for (i = 0; i < count; i++) {
roiManager("select", i);
run("Scale... ", "x=0.8 y=0.8 centered");
roiManager("update")
}
selectWindow("WT-0018.tif (red)");
roiManager("select all")
roiManager("Measure");
saveAs("Results", "/Users/hueimeichen/Desktop/red80.xls");
run("Close");
selectWindow("green");
roiManager("select all")
roiManager("Measure");
saveAs("Results", "/Users/hueimeichen/Desktop/green80.xls");
run("Close");
//close all window//
selectWindow("green");
run("Close");
selectWindow("WT-0018.tif (red)");
run("Close");
selectWindow("red");
run("Close");
selectWindow("WT-0018.tif (blue)");
run("Close");