-
Notifications
You must be signed in to change notification settings - Fork 2
/
_DKR_GroupProject.txt
177 lines (142 loc) · 4.64 KB
/
_DKR_GroupProject.txt
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
//20090624 ciclistadan
//
//used to visually compare PROJECTED, linearized spindles from an imaging session
//
//process of this macro:
//open each and find the largest dimension image
//sort based on spindle length
//adjust canvas of each to the largest dimensions
//max project all spindles that have approx the same length
//create a montage of these spindles (1-10um)
//provede a text output of how many individual spindles are in each projection
//
//image workflow:
//this is used in conjunction with several other macros, typical workflow includes
//1.)_DKR_2umProjection.txt: auto project a spindle-localized stack (use danbar AutoPrj button)
//2.)_DKR_Straighten_Spindle_Batch.txt: linearizes the spindle, output image of linearized spindle
//3a.)_DKR_GroupProjector.txt: groups linearizer spindles based on length, projects each grouping, and create a montage
//3b.)_DKR_SpindleSortedMontage.txt: adjusts canvas size of all linearized spindles, sorts them, and creates a montage
function setBackground();
macro "group project"{
setFont("SansSerif", 10, " antialiased");
run("Colors...", "foreground=white background=black selection=yellow");
// get the directory and save the file names to an array
dir1 = getDirectory("Choose source directory");
if (dir1=="")
exit("No directory available");
prelist = getFileList(dir1);
//count only tifs
tifs=0;
for(i=0;i<prelist.length;i++){
if(endsWith(prelist[i],"tif") || endsWith(prelist[i],"TIF")){
tifs++;
}
}
//make another list, only with the tif images
j=0;
list = newArray(tifs);
for(i=0;i<prelist.length;i++){
if(endsWith(prelist[i],"tif") || endsWith(prelist[i],"TIF")){
list[j] = prelist[i];
j++;
}
}
//search for the largest image
widthmax = 0;
heightmax = 0;
spindle = newArray(list.length);
for(i=0;i<list.length;i++){
open(dir1+list[i]);
selectWindow(list[i]);
getDimensions(width, height, channels, slices, frames);
getPixelSize(unit, pixelWidth, pixelHeight);
spindle[i]=width;
if(width > widthmax) {
widthmax = width;
}
if(height > heightmax) {
heightmax = height;
}
close();
}
//sort this array of images based on their width (spindle length)
do{
//search through the entire array of lengths for out of order until none are found
swap=0;
for(i=0;i<(spindle.length-1);i++){
//check to see if they are out of order, swap if they are
if(spindle[i] > spindle[i+1]){
temp = spindle[i+1];
spindle[i+1] = spindle[i];
spindle[i] = temp;
temp = list[i+1];
list[i+1] = list[i];
list[i] = temp;
swap++;
}
}
} while(swap>0);
//now we have a sorted list of spindles
//open all images with a similar spindle length, project then, save the projection, and close it, repeat for all lengths 1-10um
//open each image, change the canvas size to max height and width and set the new background appropriately
//do this for each desired spindle length
for(s=1;s<11;s++){
slices=0;
//scan spindle[i] list to see if it the correct length
for(i=0;i<spindle.length;i++){
//if it is the correct spindle, open it, change the canvas size, set its background, and go on to the next one
if(round(spindle[i]*pixelWidth)==s){
open(dir1+list[i]);
selectWindow(list[i]);
run("Canvas Size...", "width="+widthmax+" height="+heightmax+" position=Center zero");
setBackground();
slices++;
}
}
print("there are "+slices+" spindles of length "+s);
//project all open spindles (now all the same size) and save it for later
if(slices>1){
run("Images to Stack");
run("Z Project...", "start=1 stop="+slices+" projection=[Max Intensity]");
saveAs("Tif", dir1+s+"um spindles");
close();
selectWindow("Stack");
close();
}
else if(slices==1){
saveAs("Tif", dir1+s+"um spindles");
close();
}
else{
newImage("composite", "32-bit Black", widthmax, heightmax, 1);
setBackground();
saveAs("Tif", dir1+s+"um spindles");
close();
}
}
//reopen the projected images, combine into a stack and then make a montage
for(s=1;s<11;s++){
open(dir1+s+"um spindles.tif");
}
run("Images to Stack", "name=Stack");
run("Make Montage...", "columns=1 rows=10 scale=1 first=1 last=10 increment=1 border=1 ");
run("royal_whiteout");
run("Enhance Contrast", "saturated=0.5");
run("Set... ", "zoom=300");
selectWindow("Stack");
close();
}
function setBackground(){
getDimensions(width, height, channels, slices, frames);
BACKGROUND = 32768;
x=0;
y=0;
for(y=0;y<heightmax;y++){
for(x=0;x<widthmax;x++){
value = getPixel(x,y);
if(value==0){
setPixel(x,y,BACKGROUND);
}
}
}
}