Skip to content

Commit

Permalink
Add test for new fast correlation
Browse files Browse the repository at this point in the history
  • Loading branch information
jni committed Mar 9, 2017
1 parent 641d0a0 commit 878c14e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions skan/test/test_vendored_correlate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from time import time
from functools import reduce
import numpy as np
from skan.vendored import thresholding as th
from skimage.transform import integral_image
from scipy import ndimage as ndi


class Timer:
Expand All @@ -25,3 +28,16 @@ def test_fast_sauvola():
with Timer() as t1:
th.threshold_sauvola(image, window_size=w1)
assert t1.interval < 2 * t0.interval


def test_reference_correlation():
ndim = 4
shape = np.random.randint(0, 20, size=ndim)
x = np.random.random(shape)
kern = reduce(np.outer, [[-1, 0, 0, 1]] * ndim).reshape((4,) * ndim)
px = np.pad(x, (2, 1), mode='reflect')
pxi = integral_image(px)
mean_fast = th.correlate_nonzeros(pxi, kern / 3 ** ndim)
mean_ref = ndi.correlate(x, np.ones((3,) * ndim) / 3 ** ndim,
mode='mirror')
np.testing.assert_allclose(mean_fast, mean_ref)

0 comments on commit 878c14e

Please sign in to comment.