-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFolder_Apply_classifier_Weka.ijm
86 lines (64 loc) · 2.76 KB
/
Folder_Apply_classifier_Weka.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
run("Set Measurements...", "area mean standard modal min centroid center perimeter bounding fit shape feret's integrated median skewness kurtosis stack area_fraction display redirect=None decimal=3");
close("*");
setOption("JFileChooser", true);
dir_results= getDirectory("The folder of the results");
setOption("JFileChooser", false);
//set options and choose folder containing cells
setOption("JFileChooser", true);
dir= getDirectory("Cell images?");
setOption("JFileChooser", false);
//Set label saving folder
setOption("JFileChooser", true);
dir_save= getDirectory("Folder where to save labels");
setOption("JFileChooser", false);
//Set classifier folder
setOption("JFileChooser", true);
dir_clasificador= getDirectory("Folder where classifier is stored");
setOption("JFileChooser", false);
//Ask for model name
nombre_modelo ="";
Dialog.create("Write full model name including .arff or .model");
Dialog.addString(nombre_modelo, "Model name");
Dialog.show();
nombre_modelo = Dialog.getString();
//set for loop inside image folder
imagenames=getFileList(dir);
nbimages=lengthOf(imagenames);
for(image=0; image<nbimages; image++) {
name=imagenames[image];
totnamelength=lengthOf(name);
namelength=totnamelength-4;
name1=substring(name, 0, namelength);
extension=substring(name, namelength, totnamelength);
if(extension==".tif" || extension==".nd2" || extension==".czi" ) {
open(dir+File.separator+name);
run("Brightness/Contrast...");
run("Enhance Contrast", "saturated=0.35");
lista = getList("image.titles");
Array.print(lista);
getPixelSize (unit,pw,ph);
//Call and run weka
run("Advanced Weka Segmentation");
call("trainableSegmentation.Weka_Segmentation.setFeature", "Structure=true");
call("trainableSegmentation.Weka_Segmentation.setFeature", "Entropy=true");
call("trainableSegmentation.Weka_Segmentation.setFeature", "Neighbors=true");
wait(500);
//Load classifier.
clasificador = dir_clasificador+nombre_modelo;
call("trainableSegmentation.Weka_Segmentation.loadClassifier", clasificador);
call("trainableSegmentation.Weka_Segmentation.changeClassName", "0", "background");
call("trainableSegmentation.Weka_Segmentation.changeClassName", "1", "segmentation");
call("trainableSegmentation.Weka_Segmentation.getResult");
wait(200);
selectImage("Classified image");
run("16-bit");
setAutoThreshold("Default dark no-reset");
//run("Threshold...");
setOption("BlackBackground", true);
run("Convert to Mask");
saveAs("Tiff", dir_save+name);
run("Analyze Particles...", "size=0.2-Infinity display clear include composite");
saveAs("Results", dir_results+"results_a_"+name+".csv");
close("*");
}
}