-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathrotateOverwriteOiginal.py
More file actions
64 lines (48 loc) · 1.76 KB
/
rotateOverwriteOiginal.py
File metadata and controls
64 lines (48 loc) · 1.76 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
56
57
58
59
60
61
62
63
# rotateOverwriteOriginal.py
# ==========================
#
# Rotate an image on the GPU
#
# Author: Robert Haase, [email protected]
# October 2019
#########################################
from ij import IJ;
from net.haesleinhuepf.clij2 import CLIJ2;
from net.haesleinhuepf.clij.clearcl import ClearCLImage
from net.imglib2.realtransform import AffineTransform2D;
from java.lang import Math;
from ij import ImagePlus;
IJ.run("Close All");
# load example image
# imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
imp = IJ.openImage("c:/structure/data/blobs.tif");
IJ.run(imp, "32-bit", "");
imp.show();
# init GPU
clij2 = CLIJ2.getInstance();
# push image to GPU; we're using images instead of buffers
# because they suppport interpolation
input = clij2.convert(imp, ClearCLImage);
# reserve memory for output, same size and type as input
temp = clij2.create(input);
#[input.getWidth(), input.getHeight()], input.getNativeType());
# reserve memory for the resulting video of the rotating input
result = clij2.create([input.getWidth(), input.getHeight(), 360], input.getChannelDataType());
for i in range(0, 360):
at = AffineTransform2D();
at.translate(-input.getWidth() / 2, -input.getHeight() / 2);
at.rotate(i / 180.0 * Math.PI);
at.translate(input.getWidth() / 2, input.getHeight() / 2);
# Execute operation on GPU
clij2.affineTransform2D(input, temp, at);
# never overwrite the original with the rotated image!
# this is just an academic example to show what can go wrong
clij2.copy(temp, input);
# copy the resulting rotated image in the right plane in the
# final video stack
clij2.copySlice(temp, result, i);
# show result
clij2.convert(result, ImagePlus).show();
IJ.setMinAndMax(0, 255);
# clean up
clij2.clear();