Exemplo n.º 1
0
def test_specific_wavelet():
    a = dtwavexfm2_np(mandrill,
                      biort=biort('antonini'),
                      qshift=qshift('qshift_06'))
    b = dtwavexfm2_cl(mandrill,
                      biort=biort('antonini'),
                      qshift=qshift('qshift_06'))
    _compare_transforms(a, b)
Exemplo n.º 2
0
def test_equal_numpy_qshift1():
    ha = qshift('qshift_c')[0]
    hb = qshift('qshift_c')[1]
    ref = np_coldfilt(mandrill.T, ha, hb).T
    y_op = rowdfilt(mandrill_t, ha, hb)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
Exemplo n.º 3
0
def test_modified():
    a = dtwavexfm2_np(mandrill,
                      biort=biort('near_sym_b_bp'),
                      qshift=qshift('qshift_b_bp'))
    b = dtwavexfm2_cl(mandrill,
                      biort=biort('near_sym_b_bp'),
                      qshift=qshift('qshift_b_bp'))
    _compare_transforms(a, b)
Exemplo n.º 4
0
def test_equal_numpy_qshift1():
    ha = qshift('qshift_c')[0]
    hb = qshift('qshift_c')[1]
    ref = np_colifilt(mandrill, ha, hb)
    y_op = colifilt(mandrill_t, ha, hb)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
Exemplo n.º 5
0
def test_equal_small_in():
    ha = qshift('qshift_b')[0]
    hb = qshift('qshift_b')[1]
    im = mandrill[0:4,0:4]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_coldfilt(im, ha, hb)
    y_op = coldfilt(im_t, ha, hb)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
Exemplo n.º 6
0
def test_equal_small_in():
    ha = qshift('qshift_b')[0]
    hb = qshift('qshift_b')[1]
    im = mandrill[0:4, 0:4]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_colifilt(im, ha, hb)
    y_op = colifilt(im_t, ha, hb)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
Exemplo n.º 7
0
def test_equal_numpy_qshift2():
    ha = qshift('qshift_c')[0]
    hb = qshift('qshift_c')[1]
    im = mandrill[:508, :504]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_coldfilt(im.T, ha, hb).T
    y_op = rowdfilt(im_t, ha, hb)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
Exemplo n.º 8
0
def test_equal_numpy_qshift2():
    ha = qshift('qshift_c')[0]
    hb = qshift('qshift_c')[1]
    im = mandrill[:508, :504]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_coldfilt(im.T, ha, hb).T
    y_op = rowdfilt(im_t, ha, hb)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
Exemplo n.º 9
0
def test_equal_numpy_qshift1():
    h = qshift('qshift_c')[0]
    ref = np_colfilter(mandrill.T, h).T
    y_op = rowfilter(mandrill_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
Exemplo n.º 10
0
def test_coldfilt():
    h0o, g0o, h1o, g1o = biort('near_sym_b')
    h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
    A = colifilt(mandrill, g0b, g0a)
    assert_almost_equal_to_summary(A,
                                   verif['mandrill_colifilt'],
                                   tolerance=TOLERANCE)
Exemplo n.º 11
0
def test_simple_level_4_recon_custom_wavelets():
    # Test for perfect reconstruction with 3 levels
    b = biort('legall')
    q = qshift('qshift_06')
    Yl, Yh = dtwavexfm3(ellipsoid, 4, biort=b, qshift=q)
    ellipsoid_recon = dtwaveifm3(Yl, Yh, biort=b, qshift=q)
    assert ellipsoid.size == ellipsoid_recon.size
    assert np.max(np.abs(ellipsoid - ellipsoid_recon)) < TOLERANCE
Exemplo n.º 12
0
def test_simple_level_4_recon_custom_wavelets():
    # Test for perfect reconstruction with 3 levels
    b = biort('legall')
    q = qshift('qshift_06')
    Yl, Yh = dtwavexfm3(ellipsoid, 4, biort=b, qshift=q)
    ellipsoid_recon = dtwaveifm3(Yl, Yh, biort=b, qshift=q)
    assert ellipsoid.size == ellipsoid_recon.size
    assert np.max(np.abs(ellipsoid - ellipsoid_recon)) < TOLERANCE
Exemplo n.º 13
0
def test_equal_numpy_qshift2():
    h = qshift('qshift_c')[0]
    im = mandrill[52:407, 30:401]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_colfilter(im, h)
    y_op = colfilter(im_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
Exemplo n.º 14
0
def test_equal_numpy_qshift2():
    h = qshift('qshift_c')[0]
    im = mandrill[15:307, 40:267]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_colfilter(im.T, h).T
    y_op = rowfilter(im_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
Exemplo n.º 15
0
def main():
    GRID_SIZE = 128
    SPHERE_RAD = int(0.45 * GRID_SIZE) + 0.5

    # Compute an image of the sphere
    grid = np.arange(-(GRID_SIZE>>1), GRID_SIZE>>1)
    X, Y, Z = np.meshgrid(grid, grid, grid)
    r = np.sqrt(X*X + Y*Y + Z*Z)
    sphere = (0.5 + np.clip(SPHERE_RAD-r, -0.5, 0.5)).astype(np.float32)

    # Specify number of levels and wavelet family to use
    nlevels = 2
    b = biort('near_sym_a')
    q = qshift('qshift_a')

    # Form the DT-CWT of the sphere. We use discard_level_1 since we're
    # uninterested in the inverse transform and this saves us some memory.
    Yl, Yh = dtwavexfm3(sphere, nlevels, b, q, discard_level_1=False)

    # Plot maxima
    figure(figsize=(8,8))

    ax = gcf().add_subplot(1,1,1, projection='3d')
    ax.set_aspect('equal')
    ax.view_init(35, 75)

    # Plot unit sphere +ve octant
    thetas = np.linspace(0, np.pi/2, 10)
    phis = np.linspace(0, np.pi/2, 10)


    tris = []
    rad = 0.99 # so that points plotted latter are not z-clipped
    for t1, t2 in zip(thetas[:-1], thetas[1:]):
        for p1, p2 in zip(phis[:-1], phis[1:]):
            tris.append([
                sphere_to_xyz(rad, t1, p1),
                sphere_to_xyz(rad, t1, p2),
                sphere_to_xyz(rad, t2, p2),
                sphere_to_xyz(rad, t2, p1),
                ])

    sphere = Poly3DCollection(tris, facecolor='w', edgecolor=(0.6,0.6,0.6))
    ax.add_collection3d(sphere)

    locs = []
    scale = 1.1
    for idx in range(Yh[-1].shape[3]):
        Z = Yh[-1][:,:,:,idx]
        C = np.abs(Z)
        max_loc = np.asarray(np.unravel_index(np.argmax(C), C.shape)) - np.asarray(C.shape)*0.5
        max_loc /= np.sqrt(np.sum(max_loc * max_loc))

        # Only record directions in the +ve octant (or those from the -ve quadrant
        # which can be flipped).
        if np.all(np.sign(max_loc) == 1):
            locs.append(max_loc)
            ax.text(max_loc[0] * scale, max_loc[1] * scale, max_loc[2] * scale, str(idx+1))
        elif np.all(np.sign(max_loc) == -1):
            locs.append(-max_loc)
            ax.text(-max_loc[0] * scale, -max_loc[1] * scale, -max_loc[2] * scale, str(idx+1))

            # Plot all directions as a scatter plot
    locs = np.asarray(locs)
    ax.scatter(locs[:,0], locs[:,1], locs[:,2], c=np.arange(locs.shape[0]))

    w = 1.1
    ax.auto_scale_xyz([0, w], [0, w], [0, w])

    legend()
    title('3D DT-CWT subband directions for +ve hemisphere quadrant')
    tight_layout()

    show()
Exemplo n.º 16
0
def test_wrong_type_b():
    with raises(ValueError):
        qshift('antonini')
Exemplo n.º 17
0
def test_qshift():
    h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
    y = coldfilt(lena, h1b, h1b)
    z = coldfilt_gold(lena, h1b, h1a)
    assert_almost_equal(y, z)
Exemplo n.º 18
0
def test_wrong_type_b():
    with raises(ValueError):
        qshift('antonini')
Exemplo n.º 19
0
def test_qshift_d():
    coeffs = qshift('qshift_d')
    assert len(coeffs) == 8
    for v in coeffs:
        assert v.shape[0] == 18
Exemplo n.º 20
0
def test_qshift_odd_len_input_2():
    h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
    y = colifilt(mandrill, h1a[1:-1], h1b[1:-1])
    z = colifilt_gold(mandrill, h1a[1:-1], h1b[1:-1])
    assert_almost_equal(y, z)
Exemplo n.º 21
0
def test_qshift():
    y = colfilter(mandrill, qshift('qshift_a')[0])
    assert y.shape == (mandrill.shape[0] + 1, mandrill.shape[1])

    z = colfilter_gold(mandrill, qshift('qshift_a')[0])
    assert_almost_equal(y, z)
Exemplo n.º 22
0
def test_qshift():
    h = qshift('qshift_a')[0]
    y_op = colfilter(mandrill_t, h)
    assert y_op.get_shape()[1:] == (mandrill.shape[0]+1, mandrill.shape[1])
Exemplo n.º 23
0
def test_simple_custom_filter():
    vec = np.random.rand(630)
    Yl, Yh = dtwavexfm(vec, 4, biort('legall'), qshift('qshift_06'))
    vec_recon = dtwaveifm(Yl, Yh, biort('legall'), qshift('qshift_06'))
    assert np.max(np.abs(vec_recon - vec)) < TOLERANCE
Exemplo n.º 24
0
def test_reconstruct_custom_filter():
    # Reconstruction up to tolerance
    Yl, Yh = dtwavexfm2(lena, 4, biort('legall'), qshift('qshift_06'))
    lena_recon = dtwaveifm2(Yl, Yh, biort('legall'), qshift('qshift_06'))
    assert np.all(np.abs(lena_recon - lena) < TOLERANCE)
Exemplo n.º 25
0
def main():
    GRID_SIZE = 128
    SPHERE_RAD = int(0.45 * GRID_SIZE) + 0.5

    # Compute an image of the sphere
    grid = np.arange(-(GRID_SIZE >> 1), GRID_SIZE >> 1)
    X, Y, Z = np.meshgrid(grid, grid, grid)
    r = np.sqrt(X * X + Y * Y + Z * Z)
    sphere = (0.5 + np.clip(SPHERE_RAD - r, -0.5, 0.5)).astype(np.float32)

    # Specify number of levels and wavelet family to use
    nlevels = 2
    b = biort('near_sym_a')
    q = qshift('qshift_a')

    # Form the DT-CWT of the sphere. We use discard_level_1 since we're
    # uninterested in the inverse transform and this saves us some memory.
    Yl, Yh = dtwavexfm3(sphere, nlevels, b, q, discard_level_1=False)

    # Plot maxima
    figure(figsize=(8, 8))

    ax = gcf().add_subplot(1, 1, 1, projection='3d')
    ax.set_aspect('equal')
    ax.view_init(35, 75)

    # Plot unit sphere +ve octant
    thetas = np.linspace(0, np.pi / 2, 10)
    phis = np.linspace(0, np.pi / 2, 10)

    tris = []
    rad = 0.99  # so that points plotted latter are not z-clipped
    for t1, t2 in zip(thetas[:-1], thetas[1:]):
        for p1, p2 in zip(phis[:-1], phis[1:]):
            tris.append([
                sphere_to_xyz(rad, t1, p1),
                sphere_to_xyz(rad, t1, p2),
                sphere_to_xyz(rad, t2, p2),
                sphere_to_xyz(rad, t2, p1),
            ])

    sphere = Poly3DCollection(tris, facecolor='w', edgecolor=(0.6, 0.6, 0.6))
    ax.add_collection3d(sphere)

    locs = []
    scale = 1.1
    for idx in range(Yh[-1].shape[3]):
        Z = Yh[-1][:, :, :, idx]
        C = np.abs(Z)
        max_loc = np.asarray(np.unravel_index(
            np.argmax(C), C.shape)) - np.asarray(C.shape) * 0.5
        max_loc /= np.sqrt(np.sum(max_loc * max_loc))

        # Only record directions in the +ve octant (or those from the -ve quadrant
        # which can be flipped).
        if np.all(np.sign(max_loc) == 1):
            locs.append(max_loc)
            ax.text(max_loc[0] * scale, max_loc[1] * scale, max_loc[2] * scale,
                    str(idx + 1))
        elif np.all(np.sign(max_loc) == -1):
            locs.append(-max_loc)
            ax.text(-max_loc[0] * scale, -max_loc[1] * scale,
                    -max_loc[2] * scale, str(idx + 1))

            # Plot all directions as a scatter plot
    locs = np.asarray(locs)
    ax.scatter(locs[:, 0], locs[:, 1], locs[:, 2], c=np.arange(locs.shape[0]))

    w = 1.1
    ax.auto_scale_xyz([0, w], [0, w], [0, w])

    legend()
    title('3D DT-CWT subband directions for +ve hemisphere quadrant')
    tight_layout()

    show()
Exemplo n.º 26
0
def test_specific_wavelet():
    Yl, Yh = dtwavexfm2(mandrill, biort=biort('antonini'), qshift=qshift('qshift_06'))
Exemplo n.º 27
0
def test_qshift():
    y = colfilter(lena, qshift('qshift_a')[0])
    assert y.shape == (lena.shape[0]+1, lena.shape[1])

    z = colfilter_gold(lena, qshift('qshift_a')[0])
    assert_almost_equal(y, z)
Exemplo n.º 28
0
def test_reconstruct_custom_filter():
    # Reconstruction up to tolerance
    Yl, Yh = dtwavexfm2(mandrill, 4, biort('legall'), qshift('qshift_06'))
    mandrill_recon = dtwaveifm2(Yl, Yh, biort('legall'), qshift('qshift_06'))
    assert np.all(np.abs(mandrill_recon - mandrill) < TOLERANCE)
Exemplo n.º 29
0
def test_real_wavelet():
    h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
    A = coldfilt(mandrill[:,:511], h1b, h1a)
    B = coldfilt_gold(mandrill[:,:511], h1b, h1a)
    assert_almost_equal(A, B)
Exemplo n.º 30
0
def test_specific_wavelet():
    Yl, Yh = dtwavexfm2(lena, biort=biort('antonini'), qshift=qshift('qshift_06'))
Exemplo n.º 31
0
def test_qshift():
    h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
    y = coldfilt(mandrill, h1b, h1b)
    z = coldfilt_gold(mandrill, h1b, h1a)
    assert_almost_equal(y, z)
Exemplo n.º 32
0
def test_reconstruct_custom_filter():
    # Reconstruction up to tolerance
    Yl, Yh = dtwavexfm2(mandrill, 4, biort("legall"), qshift("qshift_06"))
    mandrill_recon = dtwaveifm2(Yl, Yh, biort("legall"), qshift("qshift_06"))
    assert np.all(np.abs(mandrill_recon - mandrill) < TOLERANCE)
Exemplo n.º 33
0
def test_qshift():
    y = colfilter(lena, qshift('qshift_a')[0])
    assert y.shape == (lena.shape[0]+1, lena.shape[1])
Exemplo n.º 34
0
def test_simple_custom_filter():
    vec = np.random.rand(630)
    Yl, Yh = dtwavexfm(vec, 4, biort('legall'), qshift('qshift_06'))
    vec_recon = dtwaveifm(Yl, Yh, biort('legall'), qshift('qshift_06'))
    assert np.max(np.abs(vec_recon - vec)) < TOLERANCE
Exemplo n.º 35
0
def test_coldfilt():
    h0o, g0o, h1o, g1o = biort('near_sym_b')
    h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
    A = colifilt(mandrill, g0b, g0a)
    assert_almost_equal_to_summary(A, verif['mandrill_colifilt'], tolerance=TOLERANCE)
Exemplo n.º 36
0
def test_modified():
    a = dtwavexfm2_np(mandrill, biort=biort('near_sym_b_bp'), qshift=qshift('qshift_b_bp'))
    b = dtwavexfm2_cl(mandrill, biort=biort('near_sym_b_bp'), qshift=qshift('qshift_b_bp'))
    _compare_transforms(a, b)
Exemplo n.º 37
0
def test_non_exist_qshift():
    with raises(IOError):
        qshift('this-does-not-exist')
Exemplo n.º 38
0
def test_non_exist_qshift():
    with raises(IOError):
        qshift('this-does-not-exist')
Exemplo n.º 39
0
def test_real_wavelet():
    h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
    A = coldfilt(lena[:,:511], h1b, h1a)
    B = coldfilt_gold(lena[:,:511], h1b, h1a)
    assert_almost_equal(A, B)
Exemplo n.º 40
0
def test_wrong_type_b():
    qshift('antonini')
Exemplo n.º 41
0
def test_specific_wavelet():
    Yl, Yh = dtwavexfm2(mandrill, biort=biort("antonini"), qshift=qshift("qshift_06"))
Exemplo n.º 42
0
def test_qshift():
    h = qshift('qshift_a')[0]
    y_op = rowfilter(mandrill_t, h)
    assert y_op.get_shape()[1:] == (mandrill.shape[0], mandrill.shape[1]+1)
Exemplo n.º 43
0
def test_qshift():
    y = colfilter(mandrill, qshift('qshift_a')[0])
    assert y.shape == (mandrill.shape[0] + 1, mandrill.shape[1])
Exemplo n.º 44
0
def test_qshift():
    y = colfilter(mandrill, qshift('qshift_a')[0])
    assert y.shape == (mandrill.shape[0]+1, mandrill.shape[1])
Exemplo n.º 45
0
"""

from __future__ import print_function, division

import os
import timeit

import numpy as np

from dtcwt.coeffs import biort, qshift
from dtcwt.opencl.lowlevel import NoCLPresentError, get_default_queue

lena = np.load(os.path.join(os.path.dirname(__file__), '..', 'tests', 'lena.npz'))['lena']
h0o, g0o, h1o, g1o = biort('near_sym_b')
h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')

def format_time(t):
    units = (
        (60*60, 'hr'), (60, 'min'), (1, 's'), (1e-3, 'ms')
    )

    for scale, unit in units:
        if t >= scale:
            return '{0:.2f} {1}'.format(t/scale, unit)

    return '{0:.2f} {1}'.format(t*1e6, 'us')

def benchmark(statement='pass', setup='pass'):
    number, repeat = (1, 3)
    min_time = 0
Exemplo n.º 46
0
"""

from __future__ import print_function, division

import os
import timeit

import numpy as np

from dtcwt.coeffs import biort, qshift
from dtcwt.opencl.lowlevel import NoCLPresentError, get_default_queue

mandrill = np.load(os.path.join(os.path.dirname(__file__), '..', 'tests', 'mandrill.npz'))['mandrill']
h0o, g0o, h1o, g1o = biort('near_sym_b')
h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')

def format_time(t):
    units = (
        (60*60, 'hr'), (60, 'min'), (1, 's'), (1e-3, 'ms')
    )

    for scale, unit in units:
        if t >= scale:
            return '{0:.2f} {1}'.format(t/scale, unit)

    return '{0:.2f} {1}'.format(t*1e6, 'us')

def benchmark(statement='pass', setup='pass'):
    number, repeat = (1, 3)
    min_time = 0
Exemplo n.º 47
0
def test_specific_wavelet():
    a = dtwavexfm2_np(mandrill, biort=biort('antonini'), qshift=qshift('qshift_06'))
    b = dtwavexfm2_cl(mandrill, biort=biort('antonini'), qshift=qshift('qshift_06'))
    _compare_transforms(a, b)
Exemplo n.º 48
0
def test_qshift():
    y = colfilter(mandrill, qshift('qshift_a')[0])
    assert y.shape == (mandrill.shape[0]+1, mandrill.shape[1])

    z = colfilter_gold(mandrill, qshift('qshift_a')[0])
    assert_almost_equal(y, z)
Exemplo n.º 49
0
def test_non_exist_qshift():
    qshift('this-does-not-exist')
Exemplo n.º 50
0
def test_qshift_d():
    coeffs = qshift('qshift_d')
    assert len(coeffs) == 8
    for v in coeffs:
        assert v.shape[0] == 18