/
blur_batch.ijm
56 lines (43 loc) · 1.21 KB
/
blur_batch.ijm
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
// CLIJ example macro: blur_batch.ijm
//
// This macro shows how to blur a folder of
// images in the GPU.
//
// Author: Robert Haase
// November 2019
// ---------------------------------------------
run("Close All");
// set image names
input = "input";
blurred = "Blurred";
// Init GPU
run("CLIJ Macro Extensions", "cl_device=");
Ext.CLIJ_clear();
// set folders
path_to_results = "C:/structure/temp/";
// path_to_images = "/path/to/images/";
// files = getFileList(path_to_images)
// demo with online folder
path_to_images = "https://samples.fiji.sc/";
files = newArray("blobs.png", "blobs.png", "blobs.png");
// go through the folder
for (i = 0; i < lengthOf(files); i++) {
open(path_to_images + files[i]);
rename(input);
// push images to GPU
Ext.CLIJ_push(input);
// cleanup ImageJ
run("Close All");
// Blur in GPU
Ext.CLIJ_blur3D(input, blurred, 5, 5, 1);
// Get results back from GPU
Ext.CLIJ_pull(blurred);
// save result
saveAs("tif", path_to_results + files[i]);
// if your input images have different sizes, you should call clear now,
// otherwise they may be cropped because memory of former images is reused.
// Ext.CLIJ_clear();
close();
}
// Cleanup by the end
Ext.CLIJ_clear();