-
Notifications
You must be signed in to change notification settings - Fork 2
/
_DKR_SpindleSortedMontage.txt
111 lines (92 loc) · 2.97 KB
/
_DKR_SpindleSortedMontage.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
//20090624 ciclistadan
//
//used to visually compare all linearized spindles from an imaging session
//
//open each and find the largest dimension image
//adjust canvas of each to the largest dimensions
//sort these images based on their width, open them again in this order and
//combine images into a stack followed by an auto-montage
//
//image workflow:
//this is used i nconjunction with several other macros, typical workflow includes
//1.)_DKR_2umProjection.txt: auto project a spindle-localized stack
//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
macro "Spindle Sorted Montage"{
// 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);
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);
//open each image, change the canvas size to max height and width and set the new background appropriately
background = 32768;
for(i=0;i<list.length;i++){
open(dir1+list[i]);
selectWindow(list[i]);
run("Canvas Size...", "width="+widthmax+" height="+heightmax+" position=Center zero");
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);
}
}
}
}
//combine the images into a stack and then make a montage
run("Images to Stack", "name=Stack title=[]");
run("Make Montage...", "columns=1 rows="+(list.length-1)+" scale=1 first=1 last="+(list.length-1)+" increment=1 border=1 ");
}