forked from saalfeldlab/parallel-elastic-alignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open-and-export-project-intersection.bsh
89 lines (73 loc) · 2.82 KB
/
open-and-export-project-intersection.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
/**
* Call
*
* xvfb-run -a ./ImageJ-linux64 -Ddir1=<project1 directory> -Ddir2=<project2 directory> -Dexport=<export directory> -- --no-splash open-and-export-project-intersection.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.lang.Runtime;
import java.util.ArrayList;
import mpicbg.ij.TransformMeshMapping;
import mpicbg.models.CoordinateTransformMesh;
import mpicbg.models.InterpolatedCoordinateTransform;
import mpicbg.trakem2.util.Pair;
int meshResolution = 128;
runtime = Runtime.getRuntime();
System.out.println( runtime.availableProcessors() + " cores available for multi-threading" );
dir1 = System.getProperty("dir1");
dir2 = System.getProperty("dir2");
export = System.getProperty("export");
ControlWindow.setGUIEnabled(false);
project1 = Project.openFSProject(dir1 + "/project.xml", false);
project2 = Project.openFSProject(dir2 + "/project.xml", false);
layerset1 = project1.getRootLayerSet();
layerset1.setSnapshotsMode(1);
layerset2 = project2.getRootLayerSet();
layerset2.setSnapshotsMode(1);
box = layerset1.get2DBounds().union(layerset2.get2DBounds());
/* put corresponding layers into a list of Pairs */
pairs = new ArrayList();
for (layer1 : layerset1.getLayers()) {
for (layer2 : layerset2.getLayers()) {
if (layer1.getZ() == layer2.getZ()) {
pairs.add(new Pair((Object)layer1, (Object)layer2));
break;
}
}
}
/* render layers with interpolated transformations */
/* TODO do it for more than a single patch per layer */
for (int i = 0; i < pairs.size(); ++i) {
pair = pairs.get(i);
// float lambda = (i + 1.0f) / (pairs.size() + 1.0f); // for a transition range between two standalone projects
float lambda = (float)i / (float)pairs.size(); // for series of adjacent transition ranges
System.out.println("(" + pairs.get(i).a.getZ() + ", " + pairs.get(i).b.getZ() + ") : " + lambda);
/* corresponding patches */
p1 = pair.a.getDisplayables(Patch.class).get(0);
p2 = pair.b.getDisplayables(Patch.class).get(0);
/* all inclusive CoordinateTransform */
ct1 = p1.getFullCoordinateTransform();
ct2 = p2.getFullCoordinateTransform();
/* interpolant */
ct = new InterpolatedCoordinateTransform(ct1, ct2, lambda);
/* get the pixels */
ip = p1.getImageProcessor();
ip.setInterpolationMethod(ImageProcessor.BILINEAR);
ipExport = ip.createProcessor(box.width, box.height);
/* render */
mesh = new CoordinateTransformMesh(ct, meshResolution, ip.getWidth(), ip.getHeight());
mapping = new TransformMeshMapping(mesh);
mapping.mapInterpolated(ip, ipExport);
/* save */
imp = new ImagePlus( "", ipExport );
IJ.save(imp, export + "/" + p1.getTitle() + ".tif");
}
/* shutdown */
runtime.exit(0);