-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWMC_batch.ijm
114 lines (101 loc) · 4.22 KB
/
WMC_batch.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#@ File[](label="Select image files/folders", style="both", persist=false) paths
#@ String(label="File extension (eg. 'tif', leave empty to allow all files)", value="", persist=false) suffix
#@ String(label="Filter RegExp (will override extension check)", value="", persist=false) pattern
#@ Boolean(label="Use separate output directory?", value=false, persist=false) use_outdir
#@ File(label="Output directory", value="", style="directory", persist=false) outdir
#@ BigDecimal(label="Artifact diameter for gaussian blurring", value=1.8, persist=false) g_size
#@ BigDecimal(label="Rolling ball radius", value=12, persist=false) r_size
#@ BigDecimal(label="Noise tolerance level", value=20, persist=false) noise
#@ BigDecimal(label="Intensity seed for background", value=100, persist=false) low_seed
#@ BigDecimal(label="Intensity seed for foreground", value=2000, persist=false) high_seed
#@ BigDecimal(label="Prior probability for background", value=0.6, persist=false) low_bound
#@ BigDecimal(label="Prior probability for foreground", value=0.8, persist=false) high_bound
#@ BigDecimal(label="Min. std. tolerance level for foreground obj.", value=0.2, persist=false) min_std
#@ Boolean(label="Equalize image level", value=false, persist=false) equalize
#@ Boolean(label="Use paraboloid kernel for objects", value=false, persist=false) paraboloid
#@ Boolean(label="Quit afterwards", value=false, persist=false) quit
function stripExtension(path) {
dotIndex = lastIndexOf(path, ".");
if (dotIndex!=-1) {
return substring(path, 0, dotIndex);
} else {
return path;
}
}
function runWMCSegment(input, g_size, r_size, noise, low_seed, high_seed, low_bound, high_bound, min_std, equalize, paraboloid) {
//Open file without popup
run("Bio-Formats Windowless Importer", "open=[" + input + "]");
//Do the WMC Segment
if (!equalize && !paraboloid)
run("WMC Segment", "g_size=&g_size r_size=&r_size noise=&noise low_seed=&low_seed high_seed=&high_seed low_bound=&low_bound high_bound=&high_bound min_std=&min_std ");
else if (equalize && !paraboloid)
run("WMC Segment", "g_size=&g_size r_size=&r_size noise=&noise low_seed=&low_seed high_seed=&high_seed low_bound=&low_bound high_bound=&high_bound min_std=&min_std is_equalize");
else if (!equalize && paraboloid)
run("WMC Segment", "g_size=&g_size r_size=&r_size noise=&noise low_seed=&low_seed high_seed=&high_seed low_bound=&low_bound high_bound=&high_bound min_std=&min_std use_paraboloid");
else
run("WMC Segment", "g_size=&g_size r_size=&r_size noise=&noise low_seed=&low_seed high_seed=&high_seed low_bound=&low_bound high_bound=&high_bound min_std=&min_std is_equalize use_paraboloid");
//Determine output name
dir = File.getParent(input);
if(use_outdir) {
dir = outdir;
}
fname = stripExtension(File.getName(input));
ofname = dir + File.separator + fname + '_WMCMask.png';
//Save and close
saveAs("PNG", ofname);
run("Close All");
}
function processFile(file, fromFolder) {
valid = true;
if (pattern!="") {
if (!matches(file, pattern)) {
if(!fromFolder)
print(file + " doesn't match " + pattern);
valid = false;
}
} else {
if (suffix!="") {
if (!endsWith(file, suffix)) {
if(!fromFolder)
print(file + " doesn't end with " + suffix);
valid = false;
}
}
}
if (valid) {
print("Processing file " + file);
runWMCSegment(file, g_size, r_size, noise, low_seed, high_seed, low_bound, high_bound, min_std, equalize, paraboloid);
}
}
function processFolder(folder) {
fileList = getFileList(folder);
for (f=0; f<fileList.length; f++) {
file = folder + File.separator + fileList[f];
processFile(file, true);
}
}
//MAIN
if(use_outdir) {
if(!File.exists(outdir)) {
exit("Directory " + outdir + " does not exist.");
} else {
print("Using " + outdir + " as output directory.");
}
}
setBatchMode(true);
for (i=0; i<paths.length; i++) {
path=paths[i];
if (File.exists(path)) {
if (File.isDirectory(path)) {
print("Processing directory " + path);
processFolder(path);
} else {
processFile(path, false);
}
} else {
print(path + " does not exist.");
}
}
setBatchMode(false);
if (quit)
run("Quit");