-
Notifications
You must be signed in to change notification settings - Fork 0
/
NEUROP.fiji.ijm
234 lines (209 loc) · 7.58 KB
/
NEUROP.fiji.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Neurphology macro
////
//// This macro quantifies neurite length, neurite area, neurite endpoints, neurite attachment points, and soma size
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
requires("1.42k");
run("Set Measurements...", "area mean standard modal shape limit redirect=None decimal=3");
setForegroundColor(0, 0, 0);
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
rename("original");
run("Duplicate...", "title=flatten");
run("Subtract Background...", "rolling=50");
////ask whether a wizard set-up is needed
if(getBoolean("Do you want to use the set-up wizard?")==1)
{
selectWindow("original");
run("Duplicate...", "title=blurred");
selectWindow("blurred");
run("Gaussian Blur...", "sigma=1");
imageCalculator("Subtract create", "original","blurred");
rename("sub_blurred");
selectWindow("blurred");
close();
selectWindow("sub_blurred");
run("Threshold...");
waitForUser("Select a proper threshold so that all neurites are shown\nThis is your contrast level. Click ok when done");
getThreshold(lower1,upper1);
close();
selectWindow("flatten");
run("Threshold...");
waitForUser("Select a proper threshold so that all cell bodies are shown\nThis is your soma intensity. Click ok when done");
getThreshold(lower2,upper2);
print("\\Clear");
print("contrast level: " + lower1);
print("soma intensity: " + lower2);
}
else
{
}
lowc=getNumber("Please type in your contrast level, increase it if too many particles are detected", lower1);
lowi=getNumber("Please type in your soma intensity, reduce it if too little cell body gets picked up", lower2);
nwidth=getNumber("Please type in the width of your neurite in pixel. Trace Neutrite width using line to get value", 6);
cleanup=getNumber("Please enter the particle cleanup value ... Don't change it unless it is big difference", 17);
swidth=getNumber("Please type in the minimum width of your soma in pixel",10);
if(bitDepth()!=16)
{
run("16-bit");
}
else
////Background cleanup process
////detecting low contrast pixels
selectWindow("original");
run("Duplicate...", "title=blurred");
selectWindow("blurred");
run("Gaussian Blur...", "sigma=1");
imageCalculator("Subtract create", "original","blurred");
rename("sub_blurred");
selectWindow("blurred");
close();
////create a mask for low contrast pixels
selectWindow("sub_blurred");
setThreshold(0, lowc);
run("Create Mask");
rename("low_contrast");
////create a mask for low intensity pixels
selectWindow("flatten");
setThreshold(0, lowi);
run("Create Mask");
rename("low_intensity");
run("Clear Results");
selectWindow("flatten");
close();
////create a mask to remove low intensity and low contrast pixels
imageCalculator("AND create", "low_contrast","low_intensity");
rename("zero_intensity");
run("Invert");
run("16-bit");
run("Subtract...", "value=254");
selectWindow("low_intensity");
close();
selectWindow("low_contrast");
close();
selectWindow("original");
resetThreshold();
imageCalculator("Multiply create", "original","zero_intensity");
rename("new_original");
////soma detection
selectWindow("new_original");
run("Duplicate...", "title=open");
run("Minimum...", "radius="+nwidth+swidth+"");
run("Maximum...", "radius="+nwidth+"");
////sSizeminimum=getNumber("Please type in the width of your soma in pixel", 10);
////run("Analyze Particles...", "
run("Threshold...");
waitForUser("select a proper threshold and click ok");
run("Create Mask");
rename("soma");
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing summarize");
////image clean up (remove small particles and debris) and soma removal
selectWindow("new_original");
run("Duplicate...", "title=neuritesoma");
waitForUser("select a proper threshold and click ok");
run("Create Mask");
rename("neuritesoma_mask");
setBackgroundColor(0, 0, 0);
setAutoThreshold();
run("Particle Remover", "size=0-"+cleanup+" circularity=0.00-1.00 show=Nothing");
rename("neuritesoma_clean");
run("Duplicate...", "title=neurite");
selectWindow("soma");
run("Create Selection");
selectWindow("neurite");
run("Restore Selection");
run("Clear");
run("Select None");
////neurite detection
selectWindow("neurite");
setAutoThreshold();
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing summarize");
////neurite length detection
selectWindow("neuritesoma_clean");
run("Duplicate...", "title=neuritesoma_skeleton");
run("Skeletonize");
imageCalculator("Subtract create", "neuritesoma_skeleton","soma");
rename("neurite_length");
setAutoThreshold();
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing summarize");
selectWindow("neuritesoma_clean");
close();
////attachment point detection
selectWindow("soma");
run("Select None");
run("Duplicate...", "title=soma_dilate");
run("Options...", "iterations=1 black count=1");
run("Dilate");
imageCalculator("AND create", "soma_dilate","neuritesoma_skeleton");
rename("stem");
run("Duplicate...", "title=stem_erode");
run("Options...", "iterations=1 black count=7");
run("Erode");
imageCalculator("Subtract create", "stem","stem_erode");
rename("stem_points");
imageCalculator("Subtract create", "stem_points","soma");
rename("attachment_points");
setAutoThreshold();
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing summarize");
run("Options...", "iterations=1 black count=1");
run("Dilate");
selectWindow("stem");
close();
selectWindow("stem_erode");
close();
selectWindow("neuritesoma_skeleton");
close();
selectWindow("stem_points");
close();
////endpoint detection
selectWindow("neurite_length");
run("Duplicate...", "title=neurite_erode");
run("Options...", "iterations=1 black count=7");
run("Erode");
imageCalculator("Subtract create", "neurite_length","neurite_erode");
rename("tip");
imageCalculator("Subtract create", "tip","soma_dilate");
rename("endpoints");
setAutoThreshold();
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing summarize");
run("Options...", "iterations=1 black count=1");
run("Dilate");
selectWindow("neurite_erode");
close();
selectWindow("tip");
close();
selectWindow("soma_dilate");
close();
////create color-combined image for user evaluation
selectWindow("soma");
run("Select None");
selectWindow("original");
run("8-bit");
run("Merge Channels...", "red=neurite_length green=endpoints blue=soma gray=original create keep");
rename("red=neurite green=endpoints blue=soma gray=original");
run("Channels Tool...");
run("Merge Channels...", "red=neurite_length green=attachment_points blue=soma gray=original create keep");
rename("red=neurite green=attachment-points blue=soma gray=original");
run("Channels Tool...");
////close windows that are not needed anymore
selectWindow("sub_blurred");
close();
selectWindow("zero_intensity");
close();
selectWindow("open");
close();
selectWindow("new_original");
close();
selectWindow("neurite");
close();
selectWindow("neurite_length");
close();
selectWindow("soma");
close();
selectWindow("neuritesoma");
close();
selectWindow("neuritesoma_mask");
close();
selectWindow("attachment_points");
close();
selectWindow("endpoints");
close();