1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
macro "Leaf batch [k]" {
// À UTILISER POUR DES DONNÉES ORGANISÉES EN DATE/EXPÉRIMENTATEUR/IMAGES
print("\\Clear")
SourceDir = getDirectory("Choose Parent Directory ");
datelist = getFileList(SourceDir);
path = SourceDir + "/Results.txt"
f = File.open(path)
for (i=0; i<datelist.length; i++) {
namelist = getFileList(SourceDir + datelist[i]);
for (j=0; j<namelist.length; j++) {
filelist = getFileList(SourceDir + datelist[i] + namelist[j]);
for (k=0; k<filelist.length; k++) {
showProgress(k+1, filelist.length);
open(SourceDir + datelist[i] + namelist[j]+filelist[k]);
a=leafArea();
print(datelist[i] + "\t" + namelist[j] + "\t" + a );
close();
}
}
}
selectWindow("Log")
content = getInfo();
print(f, content);
File.close(f)
}
macro "Leaf area [a]"
{
leafArea();
}
function leafArea()
{
var dpi = 300;
var pixelsPerCentimeter = dpi / 2.54; // 300 dpi
run("Clear Results");
run("Set Scale...", "distance=" + pixelsPerCentimeter + " known=1 pixel=1 unit=cm");
run("Subtract Background...", "rolling=50 light");
run("Make Binary");
run("Fill Holes");
run("Remove Outliers...", "radius=10 threshold=50 which=Dark");
run("Create Selection");
run("Set Measurements...", "area redirect=None decimal=3");
run("Analyze Particles...", "size=0.02-Infinity circularity=0.00-1.00 show=Nothing display clear"); // The treshodl permits to avoid smaller particules
getStatistics(area);
// For composed leaves, we need to sum all the small areas
Sum = 0;
selectWindow("Results");
lines1 = split(getInfo(), "\n");
headings = split(lines1[0], "\t");
for (j=1; j<lines1.length; j++) {
values = split(lines1[j], "\t");
a = values[1];
sum = sum + a;
} |
Partager