-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils_bluring.py
47 lines (40 loc) · 1.66 KB
/
test_utils_bluring.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
import pytest
import numpy as np
import tensorflow as tf
from NN.utils_bluring import \
gaussian_kernel, applyBluring, extractBlured, extractBluredOne
from NN.utils import extractInterpolated
# extractBlured same as extractInterpolated after applying gaussians
# TODO: find out why the results are so numerically instable
def test_extractBlured_same():
H = 10
img = np.random.rand(H, H, 3).astype(np.float32)
points = np.array([
[0.5, 0.5], [0.1, 0.1], [0.9, 0.9], [0.1, 0.9], [0.9, 0.1], [0.7, 0.2]
]).astype(np.float32)
R = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).astype(np.float32)
imgBlured = applyBluring(img[None], gaussian_kernel(H, R))
assert imgBlured.shape == (6, H, H, 3)
blur = extractBlured(R)
blured = blur(img, points, ptR=np.full((6, 1), 1.0))
extracted = extractInterpolated(imgBlured[0, None], points[None])[0]
assert extracted.shape == blured.shape
for i, a, b in zip(range(extracted.shape[0]), extracted, blured):
diff = np.abs(a - b).max()
assert diff < 5e-2, '%d | %s != %s' % (i, a, b)
continue
return
def test_extractBluredOne_eq_extractBlured():
img = np.random.uniform(size=(10, 10, 3)).astype(np.float32)
points = np.random.uniform(size=(10, 2)).astype(np.float32)
R = np.array([1.0]).astype(np.float32)
blur = extractBlured(R)
blured = blur(img, points, ptR=np.full((10, 1), 1.0))
blurOne = extractBluredOne()
bluredOne = blurOne(img, points, R=R)
assert blured.shape == bluredOne.shape, '%s != %s' % (blured.shape, bluredOne.shape)
for i, a, b in zip(range(blured.shape[0]), blured, bluredOne):
diff = np.abs(a - b).max()
assert diff < 5e-5, '%d | %s != %s' % (i, a, b)
continue
return