-
Notifications
You must be signed in to change notification settings - Fork 0
/
Counting Macro.ijm
438 lines (390 loc) · 12.3 KB
/
Counting Macro.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
//Debut
Dialog.create("Quel process voulez vous lancer?");
Dialog.addMessage("process 1, modification sequentielle des images ");
Dialog.addMessage("process 2, analyses des images ");
Dialog.addMessage("process 1bis, modification multithread ");
Choix = newArray("Process 1: Counting", "Process 2: Co-staning","Batching");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
// PROCESS 1
if(rep == "Process 1: Counting")
{
//Calcul de l'echelle
Dialog.create("Calculate scale?");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Non", "yes");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){runMacro("echelle.ijm");}
//range
Dialog.create("Enter size range");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Oui", "Non");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){
Dialog.create("Size?");
Dialog.addMessage("Minimum/Maximum:");
Dialog.addNumber("Minimum:", 400); // modifier ici les valeurs par defauts du seuil de size
Dialog.addNumber("Maximum:", 4000); //
Dialog.addNumber("Pixel (1=YES, 0=NO):", 1);
Dialog.addMessage("Circularity?");
Dialog.addNumber("Minimum:", 0);
Dialog.addNumber("Maximum:", 1);
Dialog.show();
Min=Dialog.getNumber();
Max=Dialog.getNumber();
Pix=Dialog.getNumber();
CirMin=Dialog.getNumber();
CirMax=Dialog.getNumber();
}
path2=getDirectory("destination folder");
myFolder=getDirectory("Origin folder");
// Debut traitement
Dialog.create("Start");
Dialog.addMessage("How many image?");
Dialog.addNumber("Number:", 2);
Dialog.show();
Ans=Dialog.getNumber();
for(i=0;i<Ans;i++){ //Boucle de traitement
open("");
name=getTitle();
run("Brightness/Contrast...");
waitForUser("Select brightness/Contrast");
run("Apply LUT");
setAutoThreshold("Intermodes dark"); //mode de threshold
run("Threshold...");
waitForUser("Select threshold");
setOption("BlackBackground", true);
run("Convert to Mask");
Mini=Min; //Buffer size
Maxi=Max;
CirMini=CirMin;
CirMaxi=CirMax;
//range
Dialog.create("Change previous settings?");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Non", "Oui");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){
Dialog.create("size");
Dialog.addMessage("Minimum/Maximum: ");
Dialog.addNumber("Minimum:", 200);
Dialog.addNumber("Maximum:", 3000);
Dialog.addNumber("Pixel (1=YES, 0=NO):", 1);
Dialog.addMessage("Circularity?");
Dialog.addNumber("Minimum:", 0);
Dialog.addNumber("Maximum:", 1);
Dialog.show();
Min=Dialog.getNumber();
Max=Dialog.getNumber();
Pix=Dialog.getNumber();
CirMin=Dialog.getNumber();
CirMax=Dialog.getNumber();
}
//Fill holes
Dialog.create("Fill holes?");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Oui", "Non");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){run("Fill Holes");}
//Advanced treatment
Dialog.create("complexe?");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Non", "Oui");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){
run("Dilate");
run("Fill Holes");
run("Erode");
}
//Watershed
Dialog.create("Watershed?");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Non", "Oui");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){run("Watershed");}
//Creation de mask
Dialog.create("Mask?");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Non", "Oui");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){
setTool("freehand");
waitForUser("Selection ROI");
setBackgroundColor(0,0,0);
run("Clear Outside");
run("Create Mask");
saveAs("tiff", path2+"mask");
close();
}
//Apply a mask
Dialog.create("Apply a mask?");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Non", "Oui");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){
open("");
t1=getTitle;
imageCalculator("AND create",t1,name);
}
saveAs("tiff", path2+name);
//analyze particles, parametres
if(Pix==1)
{run("Analyze Particles...", "size=&Min-&Max pixel circularity=&CirMin-&CirMax display include add");}
if(Pix==0)
{run("Analyze Particles...", "size=&Min-&Max circularity=&CirMin-&CirMax display include add");}
Min=Mini;
Max=Maxi;
CirMin=CirMini;
CirMax=CirMaxi;
selectWindow("Results");
//saveAs("results", path2+name+" Results"); // a mettre en comm pour enlever la sav des resultats
waitForUser("Click to next step");
run("Close All");
roiManager("Save", path2+name+" ROI Manager.zip"); // a mettre en comm pour enlever la sav du ROI data
roiManager("Delete");
run("Clear Results");
}
Dialog.create("Analysis over");
Dialog.addMessage("Il n'y a plus d'image :) ");
Dialog.show();
}
// batching
if(rep == "Batching")
{
//Calcul de l'echelle
Dialog.create("Calculer l'echelle?");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Non", "Oui");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){runMacro("echelle.ijm");}
//range
Dialog.create("Enter your size range");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Oui", "Non");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){
Dialog.create("Calculer l'echelle?");
Dialog.addMessage("Minimum/Maximum:");
Dialog.addNumber("Minimum:", 100);
Dialog.addNumber("Maximum:", 3000);
Dialog.addNumber("Pixel (1=YES, 0=NO):", 1);
Dialog.addMessage("Circularity?");
Dialog.addNumber("Minimum:", 0);
Dialog.addNumber("Maximum:", 1);
Dialog.show();
Min=Dialog.getNumber();
Max=Dialog.getNumber();
Pix=Dialog.getNumber();
CirMin=Dialog.getNumber();
CirMax=Dialog.getNumber();
}
path2=getDirectory("Destination folder");
myFolder=getDirectory("Origin folder");
Dialog.create("Debut");
Dialog.addMessage("How many image?");
Dialog.addNumber("nbr:", 0);
Dialog.show();
Ans=Dialog.getNumber();
for(i=0;i<Ans;i++){
open("");
name=getTitle();
run("Brightness/Contrast...");
waitForUser("Select brightness/Contrast");
run("Apply LUT");
setAutoThreshold("Intermodes dark");
run("Threshold...");
waitForUser("Select threshold");
setOption("BlackBackground", true);
run("Convert to Mask");
Mini=Min;
Maxi=Max;
CirMini=CirMin;
CirMaxi=CirMax;
rows = 6;
columns = 1;
n = rows*columns;
labels = newArray(n);
labels[0] = "range ";
labels[1] = "Fill holes ";
labels[2] = "Advanced treatment ";
labels[3] = "Watershed ";
labels[4] = "Creation de mask ";
labels[5] = "Apply a mask ";
defaults = newArray(n);
defaults[0] = false;
defaults[1] = false;
defaults[2] = false;
defaults[3] = false;
defaults[4] = false;
defaults[5] = false;
bufferTab = newArray(n);
bufferTab[0] = false;
bufferTab[1] = false;
bufferTab[2] = false;
bufferTab[3] = false;
bufferTab[4] = false;
bufferTab[5] = false;
Dialog.create("Check your analyse details");
Dialog.addCheckboxGroup(rows,columns,labels,defaults);
Dialog.show();
bufferTab[0]=Dialog.getCheckbox();
bufferTab[1]=Dialog.getCheckbox();
bufferTab[2]=Dialog.getCheckbox();
bufferTab[3]=Dialog.getCheckbox();
bufferTab[4]=Dialog.getCheckbox();
bufferTab[5]=Dialog.getCheckbox();
for(j=0;j<6;j++)
{
if(j == 0 && bufferTab[0]== true) {Dialog.create("size?");
Dialog.addMessage("Minimum/Maximum:");
Dialog.addNumber("Minimum:", 10);
Dialog.addNumber("Maximum:", 100);
Dialog.addNumber("Pixel (1=YES, 0=NO):", 1);
Dialog.addMessage("Circularity?");
Dialog.addNumber("Minimum:", 0.4);
Dialog.addNumber("Maximum:", 1);
Dialog.show();
Min=Dialog.getNumber();
Max=Dialog.getNumber();
Pix=Dialog.getNumber();
CirMin=Dialog.getNumber();
CirMax=Dialog.getNumber();
}
if(j == 1 && bufferTab[1]== true) {run("Fill Holes");}
if(j == 2 && bufferTab[2]== true) {run("Dilate");
run("Fill Holes");
run("Erode");}
if(j == 3 && bufferTab[3]== true) {run("Watershed");}
if(j == 4 && bufferTab[4]== true) {setTool("freehand");
waitForUser("Selection ROI");
setBackgroundColor(0,0,0);
run("Clear Outside");
run("Create Mask");
saveAs("tiff", path2+"mask");
close();
waitForUser("ok");}
if(j == 5 && bufferTab[5] == true) {
waitForUser("ca marche pas");
open("");
t1=getTitle;
imageCalculator("AND create",t1,name);}
}
saveAs("tiff", path2+name);
//analyze particles
if(Pix==1)
{run("Analyze Particles...", "size=&Min-&Max pixel circularity=&CirMin-&CirMax display include add");}
if(Pix==0)
{run("Analyze Particles...", "size=&Min-&Max circularity=&CirMin-&CirMax display include add");}
Min=Mini;
Max=Maxi;
CirMin=CirMini;
CirMax=CirMaxi;
selectWindow("Results");
//saveAs("results", path2+name+" Results"); // a mettre en comm pour enlever la sav des resultats
waitForUser("Click to next step");
run("Close All");
roiManager("Save", path2+name+" ROI Manager.zip"); // a mettre en comm pour enlever la sav des resultats
roiManager("Delete");
run("Clear Results");
}
Dialog.create("Analysis over");
Dialog.addMessage("Il n'y a plus d'image :) ");
Dialog.show();
}
// PROCESS 2
if(rep == "Process 2: Co-staning")
{
Dialog.create("Enter your size range");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Oui", "Non");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){
Dialog.create("range?");
Dialog.addMessage("Minimum/Maximum:");
Dialog.addNumber("Minimum:", 200);
Dialog.addNumber("Maximum:", 2000);
Dialog.addNumber("Pixel (1=YES, 0=NO):", 1);
Dialog.addMessage("Circularity?");
Dialog.addNumber("Minimum:", 0);
Dialog.addNumber("Maximum:", 1);
Dialog.show();
Min=Dialog.getNumber();
Max=Dialog.getNumber();
Pix=Dialog.getNumber();
CirMin=Dialog.getNumber();
CirMax=Dialog.getNumber();
}
path3=getDirectory("Destination folder");
Dialog.create("Analysis");
Dialog.addMessage("How many image?");
Dialog.addNumber("nbr:", 2);
Dialog.show();
repp=Dialog.getNumber();
for(j=1;j<repp;j++){
open("");
title1=getTitle;
dotIndex=indexOf(title1, ".");
img1 = substring(title1, 0, dotIndex);
open("");
title2=getTitle;
dotIndex=indexOf(title2, ".");
img2 = substring(title2, 0, dotIndex);
//imagecalculator
imageCalculator("AND create",title1,title2);
//saveAs("results", path2+name+" Results");
saveAs("tiff", path3+img1+" AND "+img2);
//saveAs("tiff"): pour juste enregistrer et demander un nom a l'utilisateur
//open("");
waitForUser("Calcul...");
//analyze particles
if(Pix==1)
{run("Analyze Particles...", "size=&Min-&Max pixel circularity=&CirMin-&CirMax display include add");}
if(Pix==0)
{run("Analyze Particles...", "size=&Min-&Max circularity=&CirMin-&CirMax display include add");}
//verification
Dialog.create("verif?");
Dialog.addMessage(" 1 = YES, 0 = NO ");
Choix = newArray("Oui", "Non");
Dialog.addChoice("Choix:",Choix);
Dialog.show();
rep=Dialog.getChoice();
if(rep == "Oui"){
Dialog.createNonBlocking("Calcul...")
run("Merge Channels...", "c1=&title1 c2=&title2 create keep");
roiManager("Show All");
waitForUser("verification");
}
selectWindow("Results");
//saveAs("results", path3+img1+" AND "+img2+" Results"); // a mettre en comm pour enlever la sav des resultats
waitForUser("Click to next step");
run("Close All");
roiManager("Delete");
run("Clear Results");
}
Dialog.create("Analysis over");
Dialog.addMessage("Click OK to finish");
Dialog.show();
}