-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrectview.bsh
executable file
·150 lines (118 loc) · 3.87 KB
/
correctview.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* 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.AffineModel2D;
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 + "/100-199/project.xml");
layerset2 = project2.getRootLayerSet();
/* initialize ranges and transformation models */
models = new ArrayList();
models.add(new AffineModel2D());
box = layerset2.get2DBounds();
/* load transformation model */
model = new AffineModel2D();
if (!initTransform(dir + "/100-199/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 double[]{box2.x, box2.y};
max = new double[]{box2.x + box2.width - 1, box2.y + box2.height - 1};
System.out.println("Min and Max.");
System.out.println(min[0]);
System.out.println(min[1]);
System.out.println(max[0]);
System.out.println(max[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(0).createAffine();
//System.out.println(affine[0])
//affine = models.get(0);
affine = model.createAffine();
project = tryOpenProject(dir + "/100-199/project.xml");
System.out.println("final:"+affine.toString()+", 100-199");
layerset = project.getRootLayerSet();
allpatches = layerset.getDisplayables(Patch.class);
affine0= allpatches.get(0).getAffineTransform();
affine = affine0.createInverse();
for (patch : layerset.getDisplayables(Patch.class)) {
patch.getAffineTransform().preConcatenate(affine);
patch.updateInDatabase("transform");
patch.updateBucket();
}
layerset.setMinimumDimensions();
//layerset.setDimensions(box.x, box.y, box.width, box.height);
System.out.println("final:"+affine.toString()+", 100-199");
project.save();
project.destroy();
/* shutdown */
runtime.exit(0);