-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRotate.txt
45 lines (34 loc) · 1.03 KB
/
Rotate.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
function rotate_image(filepath) {
open(filepath);
getDimensions(width, height, channels, slices, frames);
line_length = height/2;
makeLine(width/2, height/4, width/2, 3*height/4);
range = 15;
run("Rotate...", " angle=-" + range);
min_std = 1000000;
for(i=-range;i<range;i++) {
getStatistics(area, mean, min, max, std, histogram);
if(min_std > std) {
min_std = std;
angle = i;
}
print(std);
run("Rotate...", " angle=1");
}
run("Rotate... ", "angle=" + (-1) * angle + " grid=1 interpolation=Bilinear stack");
run("Save");
close();
}
input_directory = getArgument;
if (input_directory=="") exit ("No argument!");
filelist = getFileList(input_directory);
for (i=0; i<filelist.length; i++) {
split_filename = split(filelist[i], ".");
if (split_filename[1] == "tif") {
str = split(filelist[i], "-");
if (str.length != 3) {
continue;
}
rotate_image(input_directory + filelist[i]);
}
}