-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edit_Cat_ROIs.ijm
executable file
·119 lines (107 loc) · 4.17 KB
/
Edit_Cat_ROIs.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
// to do : strange color error do not change on some slices
// 19/11/2011 roiManager("Set Color",NewColor); problems with IJ 1.45o, solved in 1.45p7 daily build
macro "Edit_Cat_ROIs" {
// Categories=newArray("0","1","2","3","4","5","6","7");
Categories = newArray("Default", "Axon", "AIS", "Distal Axon", "Dendrite", "Synapse1", "Synapse2", "Axon (NT)", "AIS (NT)", "Distal Axon (NT)", "Dendrite (NT)", "Synapse 1 (NT)", "Synapse 2 (NT)", "Primary", "Secondary", "Tertiary", "Cat0", "Cat1", "Cat2", "Cat3", "Cat4", "Cat5", "Cat6", "Cat7");
DefaultColors=newArray("magenta","orange", "red", "yellow", "blue", "green", "cyan", "orange", "red", "yellow", "blue", "green", "cyan", "blue", "cyan", "green", "magenta", "red", "blue", "yellow", "cyan", "grey", "orange", "#551a8b"); // last is purple
CatColors=newArray("default", "red","green", "blue","yellow", "orange", "magenta", "cyan", "grey", "white", "black");
Dialog.create("Edit categorized ROIs");
Dialog.addCheckbox("Limit to a Slice Range", false);
Dialog.addNumber("Start Slice", 1);
Dialog.addNumber("Stop Slice", nSlices);
Dialog.addMessage("\n");
Dialog.addChoice("Source Category", Categories, Categories[0]);
Dialog.addString("Custom category", "", 12);
Dialog.addCheckbox("Apply to All Categories", false);
Dialog.addMessage("\n");
Dialog.addCheckbox("Change Category", false);
Dialog.addChoice("New Category", Categories, Categories[0]);
Dialog.addString("Custom new category", "", 12);
Dialog.addMessage("\n");
Dialog.addCheckbox("Merge two Categories", false);
Dialog.addChoice("Second Category", Categories, Categories[0]);
Dialog.addChoice("Merge into Category", Categories, Categories[0]);
Dialog.addMessage("\n");
Dialog.addCheckbox("Delete ROIs", false);
Dialog.addMessage("\n");
Dialog.addCheckbox("Change Color", false);
Dialog.addChoice("New Color", CatColors, CatColors[0]);
Dialog.addMessage("\n");
Dialog.addCheckbox("Change Width", false);
Dialog.addNumber("New Width", 2,0,2,"");
Dialog.show()
SliceRange=Dialog.getCheckbox();
StartSlice=Dialog.getNumber();
StopSlice=Dialog.getNumber();
Cat=Dialog.getChoice();
CCat = Dialog.getString();
AllCat=Dialog.getCheckbox();
ChangeCat=Dialog.getCheckbox();
NewCat=Dialog.getChoice();
CNCat = Dialog.getString();
MergeCat=Dialog.getCheckbox();
SecondCat=Dialog.getChoice();
DestCat=Dialog.getChoice();
DeleteROI=Dialog.getCheckbox();
ChangeColor=Dialog.getCheckbox();
NewColor=Dialog.getChoice();
ChangeWidth=Dialog.getCheckbox();
NewWidth=Dialog.getNumber();
if (CCat != "") Cat = CCat;
if (CNCat != "") NewCat = CNCat;
if (MergeCat == true) {
NewCat = DestCat;
}
if (SliceRange == false) {
StartSlice = 1;
StopSlice = nSlices;
}
for (i=0; i<roiManager("count"); i++) {
roiManager("select", i);
Name = getInfo("selection.name");
RoiSplit = split(Name, "-");
if (RoiSplit.length < 4) {
Name = Name + "-" + 0 + "-Default";
RoiSplit = split(Name, "-");
}
CurrentSliceString = RoiSplit[0];
CurrentSlice = parseInt(CurrentSliceString);
if (CurrentSlice >= StartSlice && CurrentSlice <= StopSlice) {
CatType = RoiSplit[3];
CatName = RoiSplit[4];
// print("CatType=" + CatType + " Cat="+Cat + " CatName=" + CatName + " NewCat=" + NewCat);
if (CatName == Cat || AllCat == true || (MergeCat == true && CatName == SecondCat)) {
if (ChangeCat == true || MergeCat == true) {
// print("changing Cat");
NewCatN = getIndex(Categories, NewCat);
NewName = RoiSplit[0] + "-" + RoiSplit[1] + "-" + RoiSplit[2] + "-" + NewCatN + "-" + NewCat;
// print(NewName);
Roi.setProperty("TracingType", NewCatN);
Roi.setProperty("TypeName", NewCat);
roiManager("Rename", NewName);
roiManager("Set Color", DefaultColors[NewCatN]);
}
if (DeleteROI==true) {
roiManager("Delete");
i--;
}
if (ChangeColor == true) {
if (NewColor == "default") {
ColorIndex = getIndex(Categories, CatName);
NewColor = DefaultColors[ColorIndex];
}
roiManager("Set Color",NewColor);
}
if (ChangeWidth==true) {
roiManager("Set Line Width", NewWidth);
}
}
}
}
}
function getIndex(array, el) {
for (i = 0; i < array.length; i++) {
if (array[i] == el) return i;
}
return -1;
}