-
Notifications
You must be signed in to change notification settings - Fork 0
/
align3d_affine.bsh
executable file
·141 lines (115 loc) · 3.94 KB
/
align3d_affine.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
/**
* Call
*
* xvfb-run -a ./ImageJ-linux64 -Dproj=<trakem2 XML> -Doutdir=<out directory> -- --no-splash intersection_AffineAlign.bsh
*
* @author Stephan Saalfeld <[email protected]>
* modified by Russel Torres
* modified by Sharmishtaa Seshamani
*/
import ini.trakem2.ControlWindow;
import ini.trakem2.Project;
import ini.trakem2.display.Layer;
import ini.trakem2.display.Patch;
import ini.trakem2.utils.Filter;
/* import ini.trakem2.utils.Montage; */
import ini.trakem2.imaging.filters.NormalizeLocalContrast;
import ini.trakem2.imaging.filters.IFilter;
import ij.ImagePlus;
import java.lang.Runtime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.regex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mpicbg.trakem2.align.Align;
import mpicbg.trakem2.align.AlignTask;
import mpicbg.trakem2.align.RegularizedAffineLayerAlignment;
Project cloneProject(origProj, newdir) {
/*
clone all layers in project, generating project with new unuid,
and thus temporary directories
*/
check = new File(newdir).isDirectory();
fileobj = new File(newdir);
newProj = Project.newFSProject("blank", null, newdir, false);
System.out.println( "After opening second one..." );
newloader = newProj.getLoader();
newloader.setMipMapsRegeneration(false);
newlayerset = newProj.getRootLayerSet();
newlayerset.setSnapshotsMode(1);
origLayerSet = origProj.getRootLayerSet();
for (l: origLayerSet.getLayers()) {
newlayerset.add(l.clone(newProj, newlayerset, l.getMinimalBoundingBox(Patch.class), false, false));
}
newlayerset.setMinimumDimensions();
return newProj;
}
try {
runtime = Runtime.getRuntime();
proj = System.getProperty("proj");
dir = System.getProperty("outdir"); // TODO better handling
ControlWindow.setGUIEnabled(false);
project = cloneProject(Project.openFSProject(proj, false), dir);
layerset = project.getRootLayerSet();
layerset.setSnapshotsMode(1);
// prepare inter-section alignment
layerRange = layerset.getLayers();
fixedLayers = new HashSet();
emptyLayers = new HashSet();
// use visible patches only
filter = new Filter() {
public boolean accept(Patch patch) {
return patch.isVisible();
}
};
/* affine alignment */
System.out.println( "Inter-section affine alignment starting..." );
paramAffine = new RegularizedAffineLayerAlignment.Param();
paramAffine.ppm.sift.initialSigma = 1.6f;
paramAffine.ppm.sift.steps = 9;
paramAffine.ppm.sift.minOctaveSize = 200;
paramAffine.ppm.sift.maxOctaveSize = 2048;
paramAffine.ppm.sift.fdSize = 8;
paramAffine.ppm.sift.fdBins = 8;
paramAffine.ppm.rod = 0.92f;
paramAffine.ppm.clearCache = true;
paramAffine.ppm.maxNumThreadsSift = runtime.availableProcessors() - 1;//24;
paramAffine.maxEpsilon = 40.0f;
paramAffine.minInlierRatio = 0.10f;
paramAffine.minNumInliers = 20;
/* ModelIndex 0 = "Translation", 1 = "Rigid", 2 = "Similarity", 3 = "Affine" */
paramAffine.expectedModelIndex = 1;
paramAffine.multipleHypotheses = true;
paramAffine.rejectIdentity = false;
paramAffine.identityTolerance = 0.0f;
paramAffine.maxNumNeighbors = 10;
paramAffine.maxNumFailures = 3;
paramAffine.maxNumThreads = runtime.availableProcessors(); //runtime.availableProcessors(); TODO what is this value?
paramAffine.desiredModelIndex = 3; /* affine */
paramAffine.regularize = true;
paramAffine.maxIterationsOptimize = 2000;
paramAffine.maxPlateauwidthOptimize = 1000;
paramAffine.regularizerIndex = 1;
paramAffine.visualize = false;
/* affine regularized by 0.10 rigid */
paramAffine.lambda = 0.1f;
new RegularizedAffineLayerAlignment().exec(
paramAffine,
layerRange,
fixedLayers,
emptyLayers,
layerset.get2DBounds(),
false,
false,
filter);
layerset.setMinimumDimensions();
/* save the project */
project.saveAs(dir + "/intersection_Affine.xml", true);
}
catch (e) {
e.printStackTrace();
}
/* shutdown */
System.exit(0); // exit with bravado
runtime.exit(0);