-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathapplyVectorField.ijm
More file actions
56 lines (43 loc) · 1.45 KB
/
applyVectorField.ijm
File metadata and controls
56 lines (43 loc) · 1.45 KB
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
// This script demonstrates how to apply a vector field
// to an image in order to transform it non-rigidly
//
// Author: Robert Haase, [email protected]
// March 2019
//
run("Close All");
// get test image
open("C:/Users/rober/Desktop/NEUBIAS_circle_color_dark_background.tif");
run("32-bit");
blobs = getTitle();
// create two images describing local shift
newImage("shiftX", "32-bit black", 256, 254, 1);
shiftX = getTitle();
newImage("shiftY", "32-bit black", 256, 254, 1);
shiftY = getTitle();
// reserve memory for the result video
newImage("resultStack", "32-bit black", 256, 254, 36);
resultStack = getTitle();
// shift some of the pixels in X
selectImage("shiftX");
makeOval(20, 98, 72, 68);
run("Add...", "value=25");
run("Select None");
run("Gaussian Blur...", "sigma=15");
run("Enhance Contrast", "saturated=0.35");
// init GPU
run("CLIJ2 Macro Extensions", "cl_device=");
Ext.CLIJ2_push(blobs);
Ext.CLIJ2_push(shiftX);
Ext.CLIJ2_push(shiftY);
Ext.CLIJ2_push(resultStack);
for (i = 0; i < 36; i++) {
// change the shift from slice to slice
Ext.CLIJ2_affineTransform2D("shiftX", rotatedShiftX, "-center rotate=" + (i * 10) + " center");
// apply transform
Ext.CLIJ2_applyVectorField2D("blobs", rotatedShiftX, "shiftY", transformed);
// put resulting 2D image in the right plane
Ext.CLIJ2_copySlice(transformed, resultStack, i);
}
// get result back from GPU
Ext.CLIJ2_pull(resultStack);
run("Invert LUT");