示例#1
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)
示例#2
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)
示例#3
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)
示例#4
0
def test_equal_numpy_biort1():
    h = biort('near_sym_b')[0]
    ref = np_colfilter(mandrill, h)
    y_op = colfilter(mandrill_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
示例#5
0
def test_equal_numpy_biort1():
    h = biort('near_sym_b')[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)
示例#6
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
示例#7
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
示例#8
0
def test_equal_numpy_biort2():
    h = biort('near_sym_b')[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)
示例#9
0
def test_equal_numpy_biort2():
    h = biort('near_sym_b')[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)
示例#10
0
def test_near_sym_a():
    h0o, g0o, h1o, g1o = biort('near_sym_a')
    assert h0o.shape[0] == 5
    assert g0o.shape[0] == 7
    assert h1o.shape[0] == 7
    assert g1o.shape[0] == 5
示例#11
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)
示例#12
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)
示例#13
0
def test_biort():
    h = biort('antonini')[0]
    y_op = colfilter(mandrill_t, h)
    assert y_op.get_shape()[1:] == mandrill.shape
示例#14
0
def test_wrong_type_a():
    biort('qshift_06')
示例#15
0
def test_biort():
    h = biort('antonini')[0]
    y_op = rowfilter(mandrill_t, h)
    assert y_op.get_shape()[1:] == mandrill.shape
示例#16
0
def test_biort():
    y = colfilter(mandrill, biort('antonini')[0])
    assert y.shape == mandrill.shape
示例#17
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()
示例#18
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)
示例#19
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
示例#20
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)
示例#21
0
def test_wrong_type_a():
    with raises(ValueError):
        biort('qshift_06')
示例#22
0
def test_antonini():
    h0o, g0o, h1o, g1o = biort('antonini')
    assert h0o.shape[0] == 9
    assert g0o.shape[0] == 7
    assert h1o.shape[0] == 7
    assert g1o.shape[0] == 9
示例#23
0
def test_wrong_type_a():
    with raises(ValueError):
        biort('qshift_06')
示例#24
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()
示例#25
0
def test_non_exist_biort():
    biort('this-does-not-exist')
示例#26
0
def test_specific_wavelet():
    Yl, Yh = dtwavexfm2(lena, biort=biort('antonini'), qshift=qshift('qshift_06'))
示例#27
0
def test_antonini():
    h0o, g0o, h1o, g1o = biort('antonini')
    assert h0o.shape[0] == 9
    assert g0o.shape[0] == 7
    assert h1o.shape[0] == 7
    assert g1o.shape[0] == 9
示例#28
0
def test_biort():
    y = colfilter(mandrill, biort('antonini')[0])
    assert y.shape == mandrill.shape

    z = colfilter_gold(mandrill, biort('antonini')[0])
    assert_almost_equal(y, z)
示例#29
0
def test_near_sym_a():
    h0o, g0o, h1o, g1o = biort('near_sym_b')
    assert h0o.shape[0] == 13
    assert g0o.shape[0] == 19
    assert h1o.shape[0] == 19
    assert g1o.shape[0] == 13
示例#30
0
def test_biort():
    y = colfilter(lena, biort('antonini')[0])
    assert y.shape == lena.shape

    z = colfilter_gold(lena, biort('antonini')[0])
    assert_almost_equal(y, z)
示例#31
0
def test_specific_wavelet():
    Yl, Yh = dtwavexfm2(mandrill, biort=biort('antonini'), qshift=qshift('qshift_06'))
示例#32
0
def test_non_exist_biort():
    with raises(IOError):
        biort('this-does-not-exist')
示例#33
0
def test_biort():
    y = colfilter(lena, biort('antonini')[0])
    assert y.shape == lena.shape
示例#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
示例#35
0
def test_legall():
    h0o, g0o, h1o, g1o = biort('legall')
    assert h0o.shape[0] == 5
    assert g0o.shape[0] == 3
    assert h1o.shape[0] == 3
    assert g1o.shape[0] == 5
示例#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)
示例#37
0
def test_near_sym_a():
    h0o, g0o, h1o, g1o = biort('near_sym_b')
    assert h0o.shape[0] == 13
    assert g0o.shape[0] == 19
    assert h1o.shape[0] == 19
    assert g1o.shape[0] == 13
示例#38
0
def test_near_sym_a():
    h0o, g0o, h1o, g1o = biort('near_sym_a')
    assert h0o.shape[0] == 5
    assert g0o.shape[0] == 7
    assert h1o.shape[0] == 7
    assert g1o.shape[0] == 5
示例#39
0
def test_non_exist_biort():
    with raises(IOError):
        biort('this-does-not-exist')
示例#40
0
def test_biort():
    y = colfilter(mandrill, biort('antonini')[0])
    assert y.shape == mandrill.shape

    z = colfilter_gold(mandrill, biort('antonini')[0])
    assert_almost_equal(y, z)
示例#41
0
CPU ones.

"""

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)
示例#42
0
def test_specific_wavelet():
    Yl, Yh = dtwavexfm2(mandrill, biort=biort("antonini"), qshift=qshift("qshift_06"))
示例#43
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)
示例#44
0
def test_biort():
    y = colfilter(mandrill, biort('antonini')[0])
    assert y.shape == mandrill.shape
示例#45
0
CPU ones.

"""

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)
示例#46
0
def test_legall():
    h0o, g0o, h1o, g1o = biort('legall')
    assert h0o.shape[0] == 5
    assert g0o.shape[0] == 3
    assert h1o.shape[0] == 3
    assert g1o.shape[0] == 5