-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilopodia-counter-v4.ijm
159 lines (114 loc) · 4.03 KB
/
filopodia-counter-v4.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
run("Close All");
print("\\Clear");
run("Collect Garbage");
roiManager("reset");
run("Set Measurements...", " redirect=None decimal=3");
run("Clear Results");
// select file to be corrected
// select file(s) to be corrected
#@ File[] (label="Select the file(s) to be corrected") files ;
#@ String (label="Select filopodia channel", choices={"C1", "C2", "C3", "C4"}, style="listBox") filo
#@ String (label="Select cell channel", choices={"C1", "C2", "C3", "C4"}, style="listBox") cell
#@ File (label="Select where to save results", style="directory") results_path ;
#@ Integer (label="Prominance", value=800) prominence
//-----------------------
for (p = 0; p < lengthOf(files); p++) {
roiManager("reset");
/* groovylint-disable-next-line LineLength */
options = "open=[" + files[p] + "] autoscale color_mode=Default stack_order=XYCZT use_virtual_stack "; // here using bioformats
run("Bio-Formats", options);
name = getTitle();
getDimensions(width, height, channels, slices, frames);
run("Duplicate...", "duplicate");
rename("QC");
selectWindow(name);
if (channels > 1) {
run("Split Channels");
} else {
exit("Multi-channel image reqruired");
}
//rename windows for easier handlling
selectWindow(filo +"-"+ name);
rename("filopodia");
selectWindow(cell +"-"+ name);
rename("cell");
run("Duplicate...", " ");
// find cell outlines
selectWindow("cell");
run("Subtract Background...", "rolling=50");
setAutoThreshold("Triangle");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Invert");
run("Fill Holes");
run("Options...", "iterations=1 count=5 black do=Close");
run("Keep Largest Region");
close("cell");
selectWindow("cell-largest");
rename("cell");
run("Analyze Particles...", "exclude add");
roiManager("Select", 0);
run("Convex Hull");
run("Enlarge...", "enlarge=6");
roiManager("Add");
//find cell inside
selectWindow("cell-1");
run("Select None");
roiManager("Deselect");
run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Li dark");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Fill Holes");
run("Options...", "iterations=20 count=1 black do=Open");
run("Keep Largest Region");
close("cell-1");
selectWindow("cell-1-largest");
rename("cell-1");
run("Analyze Particles...", "exclude add");
roiManager("Select", 2);
roiManager("Update");
//measure filopodia tips
selectWindow("filopodia");
// hide cell centre
setBackgroundColor(255, 255, 255);
roiManager("Select", 2);
roiManager("Fill");
roiManager("Deselect");
run("Median...", "radius=0.5");
run("Top Hat...", "radius=2");
roiManager("Select", 1);
run("Find Maxima...", "prominence=" + prominence + " output=Count");
run("Find Maxima...", "prominence=" + prominence + " output=[Single Points]");
setResult("Filename", p, name);
//clean roiManager for QC image
roiManager("reset");
//create and save QC image
selectWindow("filopodia Maxima");
run("Watershed");
run("Analyze Particles...", "exclude add");
nRoi = roiManager("count");
print(nRoi);
for (i = 0; i < nRoi; i++) {
roiManager("Select", i);
run("Enlarge...", "enlarge=3 pixel");
roiManager("update");
}
selectWindow("QC");
Stack.setDisplayMode("composite");
setSlice(1);
run("Grays");
run("Enhance Contrast", "saturated=0.35");
setSlice(2);
run("Green");
run("Enhance Contrast", "saturated=0.35");
run("RGB Color");
close("\\Others");
rename("name");
roiManager("show all without labels");
saveAs(".tiff", results_path + File.separator + name + "_mask");
close("*");
}
selectWindow("Results");
saveAs("Results", results_path + "/results.csv");
close("Results");