-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathstatistics.py
More file actions
48 lines (33 loc) · 1.12 KB
/
statistics.py
File metadata and controls
48 lines (33 loc) · 1.12 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
# statistics.py
# =============
#
# Derive pixel statistics of an image on the GPU
#
# Author: Robert Haase, [email protected]
# October 2019
#########################################
from ij import IJ;
from net.haesleinhuepf.clij2 import CLIJ2;
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");
imp.show();
# init GPU
clij2 = CLIJ2.getInstance();
# push image to GPU
input = clij2.push(imp);
meanIntensity = clij2.sumOfAllPixels(input) / input.getWidth() / input.getHeight();
IJ.log("Mean intensity of all pixels: " + str(meanIntensity));
# reserve memory for a mask and masked image, same size and type as input
mask = clij2.create(input);
masked = clij2.create(input);
# apply threshold method on GPU
clij2.automaticThreshold(input, mask, "Otsu");
# mask the image
clij2.mask(input, mask, masked);
# determine mean intensity of masked area:
meanIntensity = clij2.sumOfAllPixels(masked) / input.getWidth() / input.getHeight();
IJ.log("Mean intensity of masked pixels: " + str(meanIntensity));
# clean up
clij2.clear();