def test_non_orthogonal_input_non_mult_4(): Y = colifilt(mandrill, (1,0,0,1), (1,0,0,1)) assert Y.shape == (mandrill.shape[0]*2, mandrill.shape[1]) Z = colifilt_gold(mandrill, (1,0,0,1), (1,0,0,1)) assert_almost_equal(Y,Z)
def test_qshift(): h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d') y = colifilt(mandrill, h1b, h1b) z = colifilt_gold(mandrill, h1b, h1a) assert_almost_equal(y, z)
def test_good_input_size(): Y = colifilt(mandrill[:,:511], (-1,1), (1,-1)) Z = colifilt_gold(mandrill[:,:511], (-1,1), (1,-1)) assert_almost_equal(Y,Z)
def test_output_size_non_mult_4(): Y = colifilt(mandrill, (-1,0,0,1), (1,0,0,-1)) assert Y.shape == (mandrill.shape[0]*2, mandrill.shape[1]) Z = colifilt_gold(mandrill, (-1,0,0,1), (1,0,0,-1)) assert_almost_equal(Y,Z)
def test_zero_input(): Y = colifilt(np.zeros_like(mandrill), (-1,1), (1,-1)) assert np.all(Y[:0] == 0)
def test_bad_input_size(): with raises(ValueError): colifilt(mandrill[:511,:], (-1,1), (1,-1))
def test_odd_filter(): with raises(ValueError): colifilt(mandrill, (-1,2,-1), (-1,2,1))
def test_different_size_h(): colifilt(lena, (-1,2,1), (-0.5,-1,2,-1,0.5))
def _level2_ifm(Yl, Yh, g0a, g0b, g1a, g1b, ext_mode, prev_level_size): """Perform level 2 or greater of the 3d inverse transform. """ # Create work area work = np.zeros(np.asanyarray(Yl.shape) * 2, dtype=Yl.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 regions of work area work[s0a, s1a, s2a] = Yl work[s0a, s1b, s2a] = c2cube(Yh[:, :, :, 0:4]) work[s0b, s1a, s2a] = c2cube(Yh[:, :, :, 4:8]) work[s0b, s1b, s2a] = c2cube(Yh[:, :, :, 8:12]) work[s0a, s1a, s2b] = c2cube(Yh[:, :, :, 12:16]) work[s0a, s1b, s2b] = c2cube(Yh[:, :, :, 16:20]) work[s0b, s1a, s2b] = c2cube(Yh[:, :, :, 20:24]) work[s0b, s1b, s2b] = c2cube(Yh[:, :, :, 24:28]) for f in xrange(work.shape[2]): # Do even Qshift filters on rows. y = colifilt(work[:, s1a, f].T, g0b, g0a) + colifilt( work[:, s1b, f].T, g1b, g1a) # Do even Qshift filters on columns. work[:, :, f] = colifilt(y[:, s0a].T, g0b, g0a) + colifilt( y[:, s0b].T, g1b, g1a) for f in xrange(work.shape[1]): # Do even Qshift filters on 3rd dim. y = work[:, f, :].T work[:, f, :] = (colifilt(y[s2a, :], g0b, g0a) + colifilt(y[s2b, :], g1b, g1a)).T # Now check if the size of the previous level is exactly twice the size of # the current level. If YES, this means we have not done the extension in # the previous level. If NO, then we have to remove the appended row / # column / frame from the previous level DTCWT coefs. prev_level_size = np.asarray(prev_level_size) curr_level_size = np.asarray(Yh.shape) if ext_mode == 4: if curr_level_size[0] * 2 != prev_level_size[0]: # Discard the top and bottom rows work = work[1:-1, :, :] if curr_level_size[1] * 2 != prev_level_size[1]: # Discard the top and bottom rows work = work[:, 1:-1, :] if curr_level_size[2] * 2 != prev_level_size[2]: # Discard the top and bottom rows work = work[:, :, 1:-1] elif ext_mode == 8: if curr_level_size[0] * 2 != prev_level_size[0]: # Discard the top and bottom rows work = work[2:-2, :, :] if curr_level_size[1] * 2 != prev_level_size[1]: # Discard the top and bottom rows work = work[:, 2:-2, :] if curr_level_size[2] * 2 != prev_level_size[2]: # Discard the top and bottom rows work = work[:, :, 2:-2] return work
def test_qshift_even_input(): h1b = np.array((-0.25, 0.5, 0.5, -0.25)) h1a = h1b[::-1] y = colifilt(mandrill, h1b, h1a) z = colifilt_gold(mandrill, h1b, h1a) assert_almost_equal(y, z)
def test_non_orthogonal_input_non_mult_4(): Y = colifilt(lena, (1,0,0,1), (1,0,0,1)) assert Y.shape == (lena.shape[0]*2, lena.shape[1]) Z = colifilt_gold(lena, (1,0,0,1), (1,0,0,1)) assert_almost_equal(Y,Z)
def test_output_size_non_mult_4(): Y = colifilt(lena, (-1,0,0,1), (1,0,0,-1)) assert Y.shape == (lena.shape[0]*2, lena.shape[1]) Z = colifilt_gold(lena, (-1,0,0,1), (1,0,0,-1)) assert_almost_equal(Y,Z)
def test_bad_input_size(): colifilt(lena[:511,:], (-1,1), (1,-1))
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)
def test_different_size_h(): with raises(ValueError): colifilt(mandrill, (-1,2,1), (-0.5,-1,2,-1,0.5))
def _level2_ifm(Yl, Yh, g0a, g0b, g1a, g1b, ext_mode, prev_level_size): """Perform level 2 or greater of the 3d inverse transform. """ # Create work area work = np.zeros(np.asanyarray(Yl.shape)*2, dtype=Yl.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 regions of work area work[s0a, s1a, s2a] = Yl work[s0a, s1b, s2a] = c2cube(Yh[:,:,:, 0:4 ]) work[s0b, s1a, s2a] = c2cube(Yh[:,:,:, 4:8 ]) work[s0b, s1b, s2a] = c2cube(Yh[:,:,:, 8:12]) work[s0a, s1a, s2b] = c2cube(Yh[:,:,:,12:16]) work[s0a, s1b, s2b] = c2cube(Yh[:,:,:,16:20]) work[s0b, s1a, s2b] = c2cube(Yh[:,:,:,20:24]) work[s0b, s1b, s2b] = c2cube(Yh[:,:,:,24:28]) for f in xrange(work.shape[2]): # Do even Qshift filters on rows. y = colifilt(work[:, s1a, f].T, g0b, g0a) + colifilt(work[:, s1b, f].T, g1b, g1a) # Do even Qshift filters on columns. work[:, :, f] = colifilt(y[:, s0a].T, g0b, g0a) + colifilt(y[:,s0b].T, g1b, g1a) for f in xrange(work.shape[1]): # Do even Qshift filters on 3rd dim. y = work[:, f, :].T work[:, f, :] = (colifilt(y[s2a, :], g0b, g0a) + colifilt(y[s2b, :], g1b, g1a)).T # Now check if the size of the previous level is exactly twice the size of # the current level. If YES, this means we have not done the extension in # the previous level. If NO, then we have to remove the appended row / # column / frame from the previous level DTCWT coefs. prev_level_size = np.asarray(prev_level_size) curr_level_size = np.asarray(Yh.shape) if ext_mode == 4: if curr_level_size[0] * 2 != prev_level_size[0]: # Discard the top and bottom rows work = work[1:-1,:,:] if curr_level_size[1] * 2 != prev_level_size[1]: # Discard the top and bottom rows work = work[:,1:-1,:] if curr_level_size[2] * 2 != prev_level_size[2]: # Discard the top and bottom rows work = work[:,:,1:-1] elif ext_mode == 8: if curr_level_size[0] * 2 != prev_level_size[0]: # Discard the top and bottom rows work = work[2:-2,:,:] if curr_level_size[1] * 2 != prev_level_size[1]: # Discard the top and bottom rows work = work[:,2:-2,:] if curr_level_size[2] * 2 != prev_level_size[2]: # Discard the top and bottom rows work = work[:,:,2:-2] return work
def test_odd_filter(): colifilt(lena, (-1,2,-1), (-1,2,1))