batch mode generates macro failure
Posted by Josep M. Lanau on Aug 05, 2008; 11:08am
URL: http://imagej.273.s1.nabble.com/batch-mode-generates-macro-failure-tp3695456.html
I have recently programmed a macro for measuring objects. Each object
(gray) in the image contains a white particle (background is black). I
measure the shortest and largest distance (if any) from this particle to
the object's surface, along with some other parameters (areas, etc.). This
macro works fine.
Now I want to run this macro in a large amount of images, so I have built
another macro that calls first one and iterates for all images in a
directory.
Everything works perfect, but as soon as add a "setBatchMode(true);" line
in any of the two macros, the first macro does not work.
Can anyone help? I do atach the macros in case you should need them.
Thank you in advance.
Josep M. Lanau
--------
// ***** MESURA BOLETS *****
// Creat: JML 01-Març-2008
// Últim modificat el: 5/08/08
macro "Mesura bolets" {
//setBatchMode(true);
nom=getTitle();
print("Imatge, Numbolet, AreaBarret, DiamBarret, PerimBarret, XBarret,
YBarret, AreaCama, XCama, YCama, DiamCama, PerimCama, Lateralitat,
Antilateralitat");
//Neteja roiManager i deselecciona tot
seleccions=roiManager("count")
if (seleccions>0) {
roiManager("Select", 0);
roiManager("Delete");
seleccions=roiManager("count");
if (seleccions>0) {
roiManager("Combine");
roiManager("Delete");
}
}
// Poso a escala
// run("Set Scale...", "distance=296 known=5 pixel=1 unit=cm global");
// Compto el número de partícules.
run("Set Measurements...", "area centroid perimeter feret's limit display
redirect=None decimal=3");
run("Clear Results");
run("Select None");
setThreshold(35, 255);
run("Analyze Particles...", "size=500-Infinity circularity=0.00-1.00
show=Nothing display clear include summarize add");
// Agafo Núm partícules i iterar:
numparticules=roiManager("count");
cas=0;
do {
run("Set Measurements...", "area centroid perimeter feret's limit display
redirect=None decimal=3");
roiManager("Select", cas);
//Duplico,
run("Enlarge...", "enlarge=1");
run("Duplicate...", "title=[barretikama"+cas+".jpg]");
run("Enlarge...", "enlarge=-1");
run("Colors...", "foreground=white background=black selection=yellow");
run("Clear Outside");
// Selecciono blanc, Mesuro cama
setThreshold(250, 255);
run("Analyze Particles...", "size=500-Infinity circularity=0.00-1.00
show=Nothing display clear include");
AreaCama=getResult("Area");
PerimCama=getResult("Perim.");
DiamCama=getResult("Feret");
XCama=getResult("X");
YCama=getResult("Y");
run("Select None");
// Seleciono blanc +gris, mesuro barret
setThreshold(50, 249);
run("Analyze Particles...", "size=500-Infinity circularity=0.00-1.00
show=Nothing display clear include");
AreaBarret=getResult("Area");
PerimBarret=getResult("Perim.");
DiamBarret=getResult("Feret");
XBarret=getResult("X");
YBarret=getResult("Y");
//Miro si hi ha forat
run("Analyze Particles...", "size=500-Infinity circularity=0.00-1.00
show=Nothing display clear");
diferencia=AreaBarret-getResult("Area");
lateralitat=0;
// si hi ha forat mesuro lateralitat
if (diferencia!=0) {
run("Duplicate...", "title=[distancies.jpg]");
run("Colors...", "foreground=black background=white selection=yellow");
setThreshold(50, 255);
run("Make Binary", "thresholded remaining black");
run("Distance Map");
run("Invert");
// wait(1500);
selectWindow("barretikama"+cas+".jpg");
setThreshold(250, 255);
run("Create Selection");
run("Set Measurements...", " min limit display redirect=distancies.jpg
decimal=3");
run("Measure");
lateralitat=getResult("Min");
selectWindow("distancies.jpg");
close();
}
selectWindow("barretikama"+cas+".jpg");
run("Select None");
run("Duplicate...", "title=[distancies2.jpg]");
run("Colors...", "foreground=black background=white selection=yellow");
setThreshold(50, 254);
run("Make Binary", "thresholded remaining black");
run("Distance Map");
run("Invert");
// wait(1500);
selectWindow("barretikama"+cas+".jpg");
setThreshold(50, 254);
run("Create Selection");
run("Set Measurements...", " min limit display redirect=distancies2.jpg
decimal=3");
run("Measure");
antilateralitat=getResult("Max");
selectWindow("distancies2.jpg");
close();
selectWindow("barretikama"+cas+".jpg");
close();
// imprimeixo resultats a log window
print(nom, cas+1, AreaBarret, DiamBarret, PerimBarret, XBarret, YBarret,
AreaCama, XCama, YCama, DiamCama, PerimCama, lateralitat, antilateralitat );
cas=cas+1;
} while (cas<numparticules);
--------
// ***** BATCH PREPARA I MESURA BOLETS *****
macro "Batch Mesura bolets" {
dir = getDirectory("Escull el directori a mesurar");
list = getFileList(dir);
//setBatchMode(true);
for (i=0; i<list.length; i++) {
path = dir+list[i];
showProgress(i, list.length);
if (!endsWith(path,"/")) open(path);
if (nImages>=1) {
run("Run...", "run=[C:\\Program
Files\\ImageJ\\macros\\XOP_MesuraBolets.txt]");
}
wait(500);
selectWindow(list[i]);
close();
}
}
}