-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathMultithreading.java
More file actions
48 lines (35 loc) · 1.21 KB
/
Multithreading.java
File metadata and controls
48 lines (35 loc) · 1.21 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
/*
* To the extent possible under law, the ImageJ developers have waived
* all copyright and related or neighboring rights to this tutorial code.
*
* See the Unlicense for details:
* https://unlicense.org/
*/
package howto.images.processing.loopbuilder;
import net.imagej.ImageJ;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.Img;
import net.imglib2.loops.LoopBuilder;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.real.DoubleType;
import java.io.IOException;
/**
* How to use the LoopBuilder running on multiple threads
*
* @author Matthias Arzt
* @author Deborah Schmidt
*/
public class Multithreading {
public static <T extends RealType<T>> void run() throws IOException {
ImageJ ij = new ImageJ();
// load example image
RandomAccessibleInterval<T> source = (Img<T>) ij.io().open(Object.class.getResource("/blobs.png").getPath());
// create result image
Img<DoubleType> target = ij.op().create().img(source, new DoubleType());
LoopBuilder.setImages( source, target ).multiThreaded().forEachPixel( ( s, t ) -> t.set( s.getRealDouble() ) );
ij.ui().show(target);
}
public static void main(String...args) throws IOException {
run();
}
}