How to "subtract" image sequence with a single image using Image Calculator in Macro?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to "subtract" image sequence with a single image using Image Calculator in Macro?

Arreis
I have a macro from here http://imagej.1557.x6.nabble.com/ImageJ-How-to-measure-multiple-ROI-in-Batch-Process-using-Macro-and-save-each-ROI-s-result-in-indivie-td5014612.html to measure multiple ROI gray values but I wanted to add an additional process that is subtracting the group of images (say 1000 images) with a single image.

Here's the macro (not written by me, see thread) and I would like to add the additional process before the run("8-bit") line.

The macro:

dir = getDirectory("Choose a directory");
fileList = getFileList(dir);
label =
newArray("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
open(dir + fileList[0]);

selections = getNumber("how many selections do you want to create?", 4);
roiManager("Reset");
for(s=1; s<=selections; s++) {
waitForUser("Create Selection " + s);
run("Add to Manager");
}

close(fileList[0]);


setBatchMode(true);
for(i=0; i<fileList.length; i++) {
open(dir + fileList[i]);
<b>I NEED IT HERE 
run("8-bit");
run("Set Measurements...", "area mean standard min bounding area_fraction
stack display redirect=None decimal=3");
for(r=0; r<selections; r++) {
if(i>0) {
IJ.renameResults(label[r], "Results");  //runs only after frist run when
there are already results tables open
}
selectWindow(fileList[i]);
roiManager("Select", r);
roiManager("Measure");
saveAs("Results", dir + label[r] + ".xls" ); //.tsv might even be a better
file extension to handle it in Excel later
IJ.renameResults("Results", label[r]);  //enables switching between the
tables since there can only be handled 1 active "Results" table in IJ
}
close(fileList[i]);
}

setBatchMode(false);


In other words, I would like to have pic0001.png minus calibrate.png, pic0002.png minus calibrate.png, pic0003.png minus calibrate.png... and so on before the result is being further processed. How do I do that? I've tried inserting this into the macro but asking me to choose a file every time.

setBatchMode(true);
for(i=0; i<fileList.length; i++) {
open(dir + fileList[i]);
<b>file1 = fileList[i];
open(file1);
id1 = getImageID();
open();
id2 = getImageID();
imageCalculator("subtract", id1, id2);
run("8-bit");
run("Set Measurements...", "area mean standard min bounding area_fraction stack display redirect=None decimal=3");
for(r=0; r<selections; r++) {
if(i>0) {
IJ.renameResults(label[r], "Results");
}
selectWindow(fileList[i]);
roiManager("Select", r);
roiManager("Measure");
saveAs("Results", dir + label[r] + ".tsv" );
IJ.renameResults("Results", label[r]);
}
close(fileList[i]);
}

setBatchMode(false);

Please Help Me!
- Love, Arreis