Example #1
0
def test_coldfilt():
    h0o, g0o, h1o, g1o = biort('near_sym_b')
    h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
    A = coldfilt(mandrill, h1b, h1a)
    assert_almost_equal_to_summary(A,
                                   verif['mandrill_coldfilt'],
                                   tolerance=TOLERANCE)
Example #2
0
def test_different_size():
    coldfilt(lena, (-0.5,-1,2,1,0.5), (-1,2,-1))
Example #3
0
def test_odd_filter():
    coldfilt(lena, (-1,2,-1), (-1,2,1))
Example #4
0
def test_different_size():
    with raises(ValueError):
        coldfilt(mandrill, (-0.5,-1,2,1,0.5), (-1,2,-1))
Example #5
0
    def forward(self, X, nlevels=3, include_scale=False):
        """Perform a *n*-level DTCWT decompostion on a 1D column vector *X* (or on
        the columns of a matrix *X*).

        :param X: 1D real array or 2D real array whose columns are to be transformed
        :param nlevels: Number of levels of wavelet decomposition

        :returns: A :py:class:`dtcwt.Pyramid`-like object representing the transform result.

        If *biort* or *qshift* are strings, they are used as an argument to the
        :py:func:`biort` or :py:func:`qshift` functions. Otherwise, they are
        interpreted as tuples of vectors giving filter coefficients. In the *biort*
        case, this should be (h0o, g0o, h1o, g1o). In the *qshift* case, this should
        be (h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b).

        .. codeauthor:: Rich Wareham <*****@*****.**>, Aug 2013
        .. codeauthor:: Nick Kingsbury, Cambridge University, May 2002
        .. codeauthor:: Cian Shaffrey, Cambridge University, May 2002

        """
        # Which wavelets are to be used?
        biort = self.biort
        qshift = self.qshift

        # Need this because colfilter and friends assumes input is 2d
        X = asfarray(X)
        if len(X.shape) == 1:
            X = np.atleast_2d(X).T

        # Try to load coefficients if biort is a string parameter
        try:
            h0o, g0o, h1o, g1o = _biort(biort)
        except TypeError:
            h0o, g0o, h1o, g1o = biort

        # Try to load coefficients if qshift is a string parameter
        try:
            h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = _qshift(qshift)
        except TypeError:
            h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift

        L = np.asanyarray(X.shape)

        # ensure that X is an even length, thus enabling it to be extended if needs be.
        if X.shape[0] % 2 != 0:
            raise ValueError("Size of input X must be a multiple of 2")

        if nlevels == 0:
            if include_scale:
                return Pyramid(X, (), ())
            else:
                return Pyramid(X, ())

        # initialise
        Yh = [None] * nlevels
        if include_scale:
            # This is only required if the user specifies scales are to be outputted
            Yscale = [None] * nlevels

        # Level 1.
        Hi = colfilter(X, h1o)
        Lo = colfilter(X, h0o)
        Yh[0] = Hi[::2, :] + 1j * Hi[1::2, :]  # Convert Hi to complex form.
        if include_scale:
            Yscale[0] = Lo

        # Levels 2 and above.
        for level in xrange(1, nlevels):
            # Check to see if height of Lo is divisable by 4, if not extend.
            if Lo.shape[0] % 4 != 0:
                Lo = np.vstack((Lo[0, :], Lo, Lo[-1, :]))

            Hi = coldfilt(Lo, h1b, h1a)
            Lo = coldfilt(Lo, h0b, h0a)

            Yh[level] = Hi[::2, :] + 1j * Hi[1::2, :]  # Convert Hi to complex form.
            if include_scale:
                Yscale[level] = Lo

        Yl = Lo

        if include_scale:
            return Pyramid(Yl, Yh, Yscale)
        else:
            return Pyramid(Yl, Yh)
Example #6
0
def test_good_input_size_non_orthogonal():
    coldfilt(lena[:,:511], (1,1), (1,1))
Example #7
0
def test_coldfilt():
    h0o, g0o, h1o, g1o = biort('near_sym_b')
    h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
    A = coldfilt(mandrill, h1b, h1a)
    assert_almost_equal_to_summary(A, verif['mandrill_coldfilt'], tolerance=TOLERANCE)
Example #8
0
def test_different_size():
    with raises(ValueError):
        coldfilt(mandrill, (-0.5, -1, 2, 1, 0.5), (-1, 2, -1))
Example #9
0
def test_bad_input_size():
    with raises(ValueError):
        coldfilt(mandrill[:511, :], (-1, 1), (1, -1))
Example #10
0
def test_output_size():
    Y = coldfilt(mandrill, (-1,1), (1,-1))
    assert Y.shape == (mandrill.shape[0]/2, mandrill.shape[1])
Example #11
0
def test_odd_filter():
    with raises(ValueError):
        coldfilt(mandrill, (-1, 2, -1), (-1, 2, 1))
Example #12
0
def test_good_input_size_non_orthogonal():
    coldfilt(mandrill[:,:511], (1,1), (1,1))
Example #13
0
def test_good_input_size():
    coldfilt(mandrill[:,:511], (-1,1), (1,-1))
Example #14
0
def test_bad_input_size():
    with raises(ValueError):
        coldfilt(mandrill[:511,:], (-1,1), (1,-1))
Example #15
0
def test_bad_input_size():
    coldfilt(lena[:511,:], (-1,1), (1,-1))
Example #16
0
def test_good_input_size():
    coldfilt(mandrill[:, :511], (-1, 1), (1, -1))
Example #17
0
def test_good_input_size():
    coldfilt(lena[:,:511], (-1,1), (1,-1))
Example #18
0
def test_good_input_size_non_orthogonal():
    coldfilt(mandrill[:, :511], (1, 1), (1, 1))
Example #19
0
def test_output_size():
    Y = coldfilt(lena, (-1,1), (1,-1))
    assert Y.shape == (lena.shape[0]/2, lena.shape[1])
Example #20
0
def test_output_size():
    Y = coldfilt(mandrill, (-1, 1), (1, -1))
    assert Y.shape == (mandrill.shape[0] / 2, mandrill.shape[1])
    def forward(self, X, nlevels=3, include_scale=False):
        """Perform a *n*-level DTCWT decompostion on a 1D column vector *X* (or on
        the columns of a matrix *X*).

        :param X: 1D real array or 2D real array whose columns are to be transformed
        :param nlevels: Number of levels of wavelet decomposition

        :returns: A :py:class:`DTCWT.Pyramid`-like object representing the transform result.

        If *biort* or *qshift* are strings, they are used as an argument to the
        :py:func:`biort` or :py:func:`qshift` functions. Otherwise, they are
        interpreted as tuples of vectors giving filter coefficients. In the *biort*
        case, this should be (h0o, g0o, h1o, g1o). In the *qshift* case, this should
        be (h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b).

        .. codeauthor:: Rich Wareham <*****@*****.**>, Aug 2013
        .. codeauthor:: Nick Kingsbury, Cambridge University, May 2002
        .. codeauthor:: Cian Shaffrey, Cambridge University, May 2002

        """
        # Which wavelets are to be used?
        biort = self.biort
        qshift = self.qshift

        # Need this because colfilter and friends assumes input is 2d
        X = asfarray(X)
        if len(X.shape) == 1:
            X = np.atleast_2d(X).T

        # Try to load coefficients if biort is a string parameter
        try:
            h0o, g0o, h1o, g1o = _biort(biort)
        except TypeError:
            h0o, g0o, h1o, g1o = biort

        # Try to load coefficients if qshift is a string parameter
        try:
            h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = _qshift(qshift)
        except TypeError:
            h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift

        L = np.asanyarray(X.shape)

        # ensure that X is an even length, thus enabling it to be extended if needs be.
        if X.shape[0] % 2 != 0:
            raise ValueError('Size of input X must be a multiple of 2')

        if nlevels == 0:
            if include_scale:
                return Pyramid(X, (), ())
            else:
                return Pyramid(X, ())

        # initialise
        Yh = [
            None,
        ] * nlevels
        if include_scale:
            # This is only required if the user specifies scales are to be outputted
            Yscale = [
                None,
            ] * nlevels

        # Level 1.
        Hi = colfilter(X, h1o)
        Lo = colfilter(X, h0o)
        Yh[0] = Hi[::2, :] + 1j * Hi[1::2, :]  # Convert Hi to complex form.
        if include_scale:
            Yscale[0] = Lo

        # Levels 2 and above.
        for level in xrange(1, nlevels):
            # Check to see if height of Lo is divisable by 4, if not extend.
            if Lo.shape[0] % 4 != 0:
                Lo = np.vstack((Lo[0, :], Lo, Lo[-1, :]))

            Hi = coldfilt(Lo, h1b, h1a)
            Lo = coldfilt(Lo, h0b, h0a)

            Yh[level] = Hi[::2, :] + 1j * Hi[
                1::2, :]  # Convert Hi to complex form.
            if include_scale:
                Yscale[level] = Lo

        Yl = Lo

        if include_scale:
            return Pyramid(Yl, Yh, Yscale)
        else:
            return Pyramid(Yl, Yh)
Example #22
0
def test_odd_filter():
    with raises(ValueError):
        coldfilt(mandrill, (-1,2,-1), (-1,2,1))