forked from saalfeldlab/parallel-elastic-alignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import-and-align.bsh
211 lines (175 loc) · 5.74 KB
/
import-and-align.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**
* Call
*
* xvfb-run -a ./ImageJ-linux64 -Ddir=<project directory> -Dfile=<import file> -- --no-splash import-and-align.bsh
*
* on the cluster with absolute paths, e.g.
*
* ${HOME}/bin/xvfb-run -a ${HOME}/packages/Fiji.app/fiji-linux64 \
* -Xms10g -Xmx10g -Ddir=${HOME}/AL-FIB-Z0712-12/0-99 \
* -Dfile=${HOME}/AL-FIB-Z0712-12/0-99/import.txt -- --no-splash \
* ${HOME}/AL-FIB-Z0712-12/AL-FIB-Z0712-12/import-and-align.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 ini.trakem2.utils.Filter;
import ij.ImagePlus;
import java.lang.Runtime;
import java.util.ArrayList;
import java.util.HashSet;
import mpicbg.trakem2.align.ElasticLayerAlignment;
import mpicbg.trakem2.align.RegularizedAffineLayerAlignment;
try {
runtime = Runtime.getRuntime();
System.out.println( runtime.availableProcessors() + " cores available for multi-threading" );
dir = System.getProperty("dir");
file = System.getProperty("file");
ControlWindow.setGUIEnabled(false);
project = Project.newFSProject("blank", null, dir, false);
loader = project.getLoader();
layerset = project.getRootLayerSet();
layerset.setSnapshotsMode(1);
/* add a reference layer (pointless gymnastik) */
layer = new Layer(project, 0, 1, layerset);
layerset.add(layer);
layer.recreateBuckets();
/* import images */
task = loader.importImages(
layerset.getLayer(0), // the first layer
file, // the absolute file path to the text file with absolute image file paths
" ", // the column separator <path> <x> <y> <section index>
1.0, // section thickness, defaults to 1
1.0, // calibration, defaults to 1
false, // whether to homogenize contrast, avoid
1.0f, // scaling factor, default to 1
0); // border width
/* wait until all images have been imported */
task.join();
// /* wait until all mipmaps are generated */
// futures = new ArrayList();
// for (p : layerset.getDisplayables(Patch.class))
// futures.add(p.updateMipMaps());
// for (f : futures)
// f.get();
/* delete reference layer if it was not part of the import range */
l0 = layerset.getLayer(0);
if (l0.getDisplayables(Patch.class).size() == 0)
layerset.remove(l0);
/* save the project */
project.saveAs(dir + "/project.xml", false);
/* prepare alignment */
layerRange = layerset.getLayers();
fixedLayers = new HashSet();
emptyLayers = new HashSet();
filter = new Filter() {
public boolean accept(Patch patch) {
return patch.isVisible();
}
};
/* affine alignment */
paramAffine = new RegularizedAffineLayerAlignment.Param();
paramAffine.ppm.sift.initialSigma = 1.6f;
paramAffine.ppm.sift.steps = 3;
paramAffine.ppm.sift.minOctaveSize = 200;
paramAffine.ppm.sift.maxOctaveSize = 1024;
paramAffine.ppm.sift.fdSize = 4;
paramAffine.ppm.sift.fdBins = 8;
paramAffine.ppm.rod = 0.92f;
paramAffine.ppm.clearCache = true;
paramAffine.ppm.maxNumThreadsSift = runtime.availableProcessors();
paramAffine.maxEpsilon = 50.0f;
paramAffine.minInlierRatio = 0.0f;
paramAffine.minNumInliers = 12;
paramAffine.expectedModelIndex = 0;
paramAffine.multipleHypotheses = true;
paramAffine.rejectIdentity = false;
paramAffine.identityTolerance = 0.0f;
paramAffine.maxNumNeighbors = 10;
paramAffine.maxNumFailures = 3;
paramAffine.maxNumThreads = runtime.availableProcessors();
paramAffine.desiredModelIndex = 3;
paramAffine.regularize = true;
paramAffine.maxIterationsOptimize = 2000;
paramAffine.maxPlateauwidthOptimize = 2000;
paramAffine.regularizerIndex = 0;
paramAffine.visualize = false;
paramAffine.lambda = 0.1f;
new RegularizedAffineLayerAlignment().exec(
paramAffine,
layerRange,
fixedLayers,
emptyLayers,
layerset.get2DBounds(),
false,
false,
filter);
paramAffine.lambda = 0.01f;
layerset.setMinimumDimensions();
new RegularizedAffineLayerAlignment().exec(
paramAffine,
layerRange,
fixedLayers,
emptyLayers,
layerset.get2DBounds(),
false,
false,
filter);
layerset.setMinimumDimensions();
/* save the project */
project.saveAs(dir + "/project.xml", true);
/* elastic alignment */
paramElastic = new ElasticLayerAlignment.Param();
paramElastic.layerScale = 0.25f;
paramElastic.searchRadius = 12;
paramElastic.blockRadius = 600;
paramElastic.resolutionSpringMesh = (int)Math.ceil((double)layerset.get2DBounds().width / 8192.0 * 32.0);
paramElastic.minR = 0.6f;
paramElastic.maxCurvatureR = 10.0f;
paramElastic.rodR = 0.92f;
paramElastic.useLocalSmoothnessFilter = true;
paramElastic.localModelIndex = 3;
paramElastic.localRegionSigma = 1000.0f;
paramElastic.maxLocalEpsilon = 1.0f;
paramElastic.maxLocalTrust = 4.0f;
paramElastic.isAligned = true;
paramElastic.maxNumFailures = 3;
paramElastic.maxNumNeighbors = 5;
paramElastic.maxNumThreads = 8;
paramElastic.desiredModelIndex = 1;
paramElastic.maxIterationsOptimize = 1000;
paramElastic.maxPlateauwidthOptimize = 200;
paramElastic.stiffnessSpringMesh = 0.25f;
paramElastic.maxStretchSpringMesh = 2000.0f;
paramElastic.maxIterationsSpringMesh = 5000;
paramElastic.maxPlateauwidthSpringMesh = 1000;
paramElastic.dampSpringMesh = 0.9f;
paramElastic.useLegacyOptimizer = false;
new ElasticLayerAlignment().exec(
paramElastic,
project,
layerRange,
fixedLayers,
emptyLayers,
layerset.get2DBounds(),
false,
false,
filter);
/* wait until all mipmaps are generated */
futures = new ArrayList();
for (p : layerset.getDisplayables(Patch.class))
futures.add(p.updateMipMaps());
for (f : futures)
f.get();
layerset.setMinimumDimensions();
/* save the project */
project.saveAs(dir + "/project.xml", true);
}
catch (e) {
e.printStackTrace();
}
/* shutdown */
runtime.exit(0);