-
Notifications
You must be signed in to change notification settings - Fork 0
/
mult_leafdims.ijm_
executable file
·79 lines (57 loc) · 2.07 KB
/
mult_leafdims.ijm_
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//multiple leaf dimensions macro
//must run through IJ GUI!!
#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".JPG") suffix
processFolder(input);
// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + File.separator + list[i]))
processFolder(input + File.separator + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
}
}
function processFile(input, output, file) {
open(input + File.separator + file);
title = getTitle();
dotIndex = indexOf(title, ".");
basename = substring(title, 0, dotIndex);
run("8-bit");
run("Auto Threshold", "method=Huang");
run("Analyze Particles...", " show=Outlines display exclude clear add summarize");
run("Particles8 ", "white morphology show=Particles minimum=0 maximum=9999999 display redirect=None");
// draw Feret's diameter and breadth for visualization
numberOfRows = nResults;
for (row = 0; row < numberOfRows; row++) {
Fx1 = getResult("FeretX1", row);
Fy1 = getResult("FeretY1", row);
Fx2 = getResult("FeretX2", row);
Fy2 = getResult("FeretY2", row);
Bx1 = getResult("BrdthX1", row);
By1 = getResult("BrdthY1", row);
Bx2 = getResult("BrdthX2", row);
By2 = getResult("BrdthY2", row);
makeLine(Fx1, Fy1, Fx2, Fy2);
run("Properties... ", "stroke=red width=1");
run("Add Selection...");
makeLine(Bx1, By1, Bx2, By2);
run("Properties... ", "stroke=blue width=1");
run("Add Selection...");
}
// Closing time-------------
saveAs("PNG", output + File.separator + file);
saveAs("Results", output + File.separator + basename + ".csv");
run("Clear Results");
print("Saving to: " + output);
close();
}
/*
* sauce:
* https://forum.image.sc/t/results-table-to-macro/28190/12
* https://www.youtube.com/watch?reload=9&v=AX4qt2NluAo
*
*/