-
Notifications
You must be signed in to change notification settings - Fork 0
/
correctviewbackup.bsh
executable file
·132 lines (104 loc) · 3.34 KB
/
correctviewbackup.bsh
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
/**
* Applies a previously estimated rigid transformation to a series of
* overlapping projects and updates their bounding boxes accordingly
* Call
*
* xvfb-run ./ImageJ-linux64 -Ddir=<projects directory> -Dstart=<first index> -Dend=<last index> -Doverlap=<overlap size> -- --no-splash apply-aligned-overlaping-projects.bsh
*
* @author Stephan Saalfeld <[email protected]>
*/
import ini.trakem2.ControlWindow;
import ini.trakem2.Project;
import ini.trakem2.display.Layer;
import ini.trakem2.display.Patch;
import ij.IJ;
import ij.ImagePlus;
import ij.process.ImageProcessor;
import java.awt.geom.AffineTransform;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import mpicbg.trakem2.transform.RigidModel2D;
import mpicbg.trakem2.transform.TranslationModel2D;
import mpicbg.trakem2.util.Pair;
Project tryOpenProject(path) {
Exception f = null;
for (int i = 0; i < 10; ++i) {
try {
project = Project.openFSProject(path, false);
if (project != null)
return project;
}
catch (e) {
f = e;
f.printStackTrace();
}
System.out.println("Trial " + i + ", failed to open project \"" + path + "\".");
Thread.sleep(1000);
}
if (f == null)
return null;
else
throw f;
}
boolean initTransform(path, transform) {
try {
reader = new BufferedReader(new FileReader(path));
transform.init(reader.readLine());
reader.close();
return true;
}
catch (e) {
return false;
}
}
runtime = Runtime.getRuntime();
System.out.println( runtime.availableProcessors() + " cores available for multi-threading" );
dir = System.getProperty("dir");
start = Integer.parseInt(System.getProperty("start"));
end = Integer.parseInt(System.getProperty("end"));
ControlWindow.setGUIEnabled(false);
/* initialize project */
project2 = tryOpenProject(dir + "/0-49/project.xml");
layerset2 = project2.getRootLayerSet();
/* initialize ranges and transformation models */
models = new ArrayList();
models.add(new RigidModel2D());
box = layerset2.get2DBounds();
/* load transformation model */
model = new RigidModel2D();
if (!initTransform(dir + "/0-49/rigidnew.txt", model))
System.out.println("Failed loading transformation.");
/* accumulate transformation model */
model.preConcatenate(models.get(models.size() - 1));
/* store transformation model */
models.add(model);
/* estimate local bounds after transformation */
box2 = layerset2.get2DBounds();
min = new float[]{box2.x, box2.y};
max = new float[]{box2.x + box2.width - 1, box2.y + box2.height - 1};
model.estimateBounds(min, max);
/* accumulate bounds */
box = box.union(new Rectangle(
(int)Math.floor(min[0]),
(int)Math.floor(min[1]),
(int)Math.ceil(max[0] + 1) - (int)Math.floor(min[0]),
(int)Math.ceil(max[1] + 1) - (int)Math.floor(min[1])));
System.out.println(model.toString());
System.out.println(box.toString());
project2.destroy();
/* re-box and apply transformation models */
affine = models.get(i).createAffine();
project = tryOpenProject(dir + "/0-49/project.xml");
System.out.println("final:"+affine.toString()+", 0 - 49"));
layerset = project.getRootLayerSet();
for (patch : layerset.getDisplayables(Patch.class)) {
patch.getAffineTransform().preConcatenate(affine);
patch.updateInDatabase("transform");
patch.updateBucket();
}
layerset.setDimensions(box.x, box.y, box.width, box.height);
project.save();
project.destroy();
/* shutdown */
runtime.exit(0);