-
Notifications
You must be signed in to change notification settings - Fork 44
/
test_histogram.py
74 lines (50 loc) · 1.5 KB
/
test_histogram.py
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
64
65
66
67
68
69
70
71
72
73
import pyclesperanto_prototype as cle
import numpy as np
def test_histogram():
test = cle.push_zyx(np.asarray([
[1, 2, 4, 4, 2, 3],
[3, 3, 4, 4, 5, 5]
]))
ref_histogram = [1, 2, 3, 4, 2]
my_histogram = cle.histogram(test, num_bins = 5)
print(my_histogram)
a = cle.pull(my_histogram)
assert (np.allclose(a, ref_histogram))
def test_histogram_3d():
test = cle.push_zyx(np.asarray([
[
[1, 2, 4, 4, 2, 3]
], [
[3, 3, 4, 4, 5, 5]
]
]))
ref_histogram = [1, 2, 3, 4, 2]
my_histogram = cle.histogram(test, num_bins = 5)
print(my_histogram)
a = cle.pull(my_histogram)
assert (np.allclose(a, ref_histogram))
def test_histogram_3d_2():
test = cle.push_zyx(np.asarray([
[
[1, 2, 4],
[4, 2, 3]
], [
[3, 3, 4],
[4, 5, 5]
]
]))
ref_histogram = [1, 2, 3, 4, 2]
my_histogram = cle.histogram(test, num_bins = 5)
print(my_histogram)
a = cle.pull(my_histogram)
assert (np.allclose(a, ref_histogram))
def test_histogram_against_scikit_image():
from skimage.data import camera
image = camera()
from skimage import exposure
hist, bc = exposure.histogram(image.ravel(), 256, source_range='image')
print(str(hist))
gpu_image = cle.push(image)
gpu_hist = cle.histogram(gpu_image, num_bins=256)
print(str(cle.pull_zyx(gpu_hist)))
assert (np.allclose(hist, cle.pull_zyx(gpu_hist)))