Пример #1
0
def test_output_size():
    Y = coldfilt(lena, (-1,1), (1,-1))
    assert Y.shape == (lena.shape[0]/2, lena.shape[1])

    Z = coldfilt_gold(lena, (-1,1), (1,-1))
    assert_almost_equal(Y, Z)
Пример #2
0
def test_good_input_size():
    A = coldfilt(lena[:,:511], (-1,1), (1,-1))
    B = coldfilt_gold(lena[:,:511], (-1,1), (1,-1))
    assert_almost_equal(A, B)
Пример #3
0
def test_good_input_size_non_orthogonal():
    A = coldfilt(lena[:,:511], (1,1), (1,1))
    B = coldfilt_gold(lena[:,:511], (1,1), (1,1))
    assert_almost_equal(A, B)
Пример #4
0
def test_bad_input_size():
    coldfilt(lena[:511,:], (-1,1), (1,-1))
Пример #5
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)
Пример #6
0
def test_different_size():
    with raises(ValueError):
        coldfilt(mandrill, (-0.5,-1,2,1,0.5), (-1,2,-1))
Пример #7
0
def test_different_size():
    coldfilt(lena, (-0.5,-1,2,1,0.5), (-1,2,-1))
Пример #8
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)
Пример #9
0
def _level2_xfm(X, h0a, h0b, h1a, h1b, ext_mode):
    """Perform level 2 or greater of the 3d transform.

    """

    if ext_mode == 4:
        if X.shape[0] % 4 != 0:
            X = np.concatenate((X[[0], :, :], X, X[[-1], :, :]), 0)
        if X.shape[1] % 4 != 0:
            X = np.concatenate((X[:, [0], :], X, X[:, [-1], :]), 1)
        if X.shape[2] % 4 != 0:
            X = np.concatenate((X[:, :, [0]], X, X[:, :, [-1]]), 2)
    elif self.ext_mode == 8:
        if X.shape[0] % 8 != 0:
            X = np.concatenate((X[(0, 0), :, :], X, X[(-1, -1), :, :]), 0)
        if X.shape[1] % 8 != 0:
            X = np.concatenate((X[:, (0, 0), :], X, X[:, (-1, -1), :]), 1)
        if X.shape[2] % 8 != 0:
            X = np.concatenate((X[:, :, (0, 0)], X, X[:, :, (-1, -1)]), 2)

    # Create work area
    work_shape = np.asanyarray(X.shape)
    work = np.zeros(work_shape, dtype=X.dtype)

    # Form some useful slices
    s0a = slice(None, work.shape[0] >> 1)
    s1a = slice(None, work.shape[1] >> 1)
    s2a = slice(None, work.shape[2] >> 1)
    s0b = slice(work.shape[0] >> 1, None)
    s1b = slice(work.shape[1] >> 1, None)
    s2b = slice(work.shape[2] >> 1, None)

    # Assign input
    work = X

    # Loop over 2nd dimension extracting 2D slice from first and 3rd dimensions
    for f in xrange(work.shape[1]):
        # extract slice (copy required because we overwrite the work array)
        y = work[:, f, :].T.copy()

        # Do even Qshift filters on 3rd dim.
        work[:, f, s2b] = coldfilt(y, h1b, h1a).T
        work[:, f, s2a] = coldfilt(y, h0b, h0a).T

    # Loop over 3rd dimension extracting 2D slice from first and 2nd dimensions
    for f in xrange(work.shape[2]):
        # Do even Qshift filters on rows.
        y1 = work[:, :, f].T
        y2 = np.vstack((coldfilt(y1, h0b, h0a), coldfilt(y1, h1b, h1a))).T

        # Do even Qshift filters on columns.
        work[s0a, :, f] = coldfilt(y2, h0b, h0a)
        work[s0b, :, f] = coldfilt(y2, h1b, h1a)

    # Return appropriate slices of output
    return (
        work[s0a, s1a, s2a],  # LLL
        np.concatenate(
            (
                cube2c(work[s0a, s1b, s2a]),  # HLL
                cube2c(work[s0b, s1a, s2a]),  # LHL
                cube2c(work[s0b, s1b, s2a]),  # HHL
                cube2c(work[s0a, s1a, s2b]),  # LLH
                cube2c(work[s0a, s1b, s2b]),  # HLH
                cube2c(work[s0b, s1a, s2b]),  # LHH
                cube2c(work[s0b, s1b, s2b]),  # HLH
            ),
            axis=3))
Пример #10
0
def test_good_input_size_non_orthogonal():
    A = coldfilt(mandrill[:,:511], (1,1), (1,1))
    B = coldfilt_gold(mandrill[:,:511], (1,1), (1,1))
    assert_almost_equal(A, B)
Пример #11
0
def test_output_size():
    Y = coldfilt(mandrill, (-1,1), (1,-1))
    assert Y.shape == (mandrill.shape[0]/2, mandrill.shape[1])

    Z = coldfilt_gold(mandrill, (-1,1), (1,-1))
    assert_almost_equal(Y, Z)
Пример #12
0
def test_good_input_size():
    A = coldfilt(mandrill[:,:511], (-1,1), (1,-1))
    B = coldfilt_gold(mandrill[:,:511], (-1,1), (1,-1))
    assert_almost_equal(A, B)
Пример #13
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)
Пример #14
0
def test_bad_input_size():
    with raises(ValueError):
        coldfilt(mandrill[:511,:], (-1,1), (1,-1))
Пример #15
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)
Пример #16
0
def test_odd_filter():
    coldfilt(lena, (-1,2,-1), (-1,2,1))
Пример #17
0
def _level2_xfm(X, h0a, h0b, h1a, h1b, ext_mode):
    """Perform level 2 or greater of the 3d transform.

    """

    if ext_mode == 4:
        if X.shape[0] % 4 != 0:
            X = np.concatenate((X[[0],:,:], X, X[[-1],:,:]), 0)
        if X.shape[1] % 4 != 0:
            X = np.concatenate((X[:,[0],:], X, X[:,[-1],:]), 1)
        if X.shape[2] % 4 != 0:
            X = np.concatenate((X[:,:,[0]], X, X[:,:,[-1]]), 2)
    elif self.ext_mode == 8:
        if X.shape[0] % 8 != 0:
            X = np.concatenate((X[(0,0),:,:], X, X[(-1,-1),:,:]), 0)
        if X.shape[1] % 8 != 0:
            X = np.concatenate((X[:,(0,0),:], X, X[:,(-1,-1),:]), 1)
        if X.shape[2] % 8 != 0:
            X = np.concatenate((X[:,:,(0,0)], X, X[:,:,(-1,-1)]), 2)

    # Create work area
    work_shape = np.asanyarray(X.shape)
    work = np.zeros(work_shape, dtype=X.dtype)

    # Form some useful slices
    s0a = slice(None, work.shape[0] >> 1)
    s1a = slice(None, work.shape[1] >> 1)
    s2a = slice(None, work.shape[2] >> 1)
    s0b = slice(work.shape[0] >> 1, None)
    s1b = slice(work.shape[1] >> 1, None)
    s2b = slice(work.shape[2] >> 1, None)

    # Assign input
    work = X

    # Loop over 2nd dimension extracting 2D slice from first and 3rd dimensions
    for f in xrange(work.shape[1]):
        # extract slice (copy required because we overwrite the work array)
        y = work[:, f, :].T.copy()

        # Do even Qshift filters on 3rd dim.
        work[:, f, s2b] = coldfilt(y, h1b, h1a).T
        work[:, f, s2a] = coldfilt(y, h0b, h0a).T

    # Loop over 3rd dimension extracting 2D slice from first and 2nd dimensions
    for f in xrange(work.shape[2]):
        # Do even Qshift filters on rows.
        y1 = work[:, :, f].T
        y2 = np.vstack((coldfilt(y1, h0b, h0a), coldfilt(y1, h1b, h1a))).T

        # Do even Qshift filters on columns.
        work[s0a, :, f] = coldfilt(y2, h0b, h0a)
        work[s0b, :, f] = coldfilt(y2, h1b, h1a)

    # Return appropriate slices of output
    return (
        work[s0a, s1a, s2a],                # LLL
        np.concatenate((
            cube2c(work[s0a, s1b, s2a]),    # HLL
            cube2c(work[s0b, s1a, s2a]),    # LHL
            cube2c(work[s0b, s1b, s2a]),    # HHL
            cube2c(work[s0a, s1a, s2b]),    # LLH
            cube2c(work[s0a, s1b, s2b]),    # HLH
            cube2c(work[s0b, s1a, s2b]),    # LHH
            cube2c(work[s0b, s1b, s2b]),    # HLH
            ), axis=3)
        )
Пример #18
0
def test_odd_filter():
    with raises(ValueError):
        coldfilt(mandrill, (-1,2,-1), (-1,2,1))