Esempio n. 1
0
    def _test_wavedec2(self, wavelet, shape, levels):
        import pywt
        ll = int(np.log2(max(shape)))
        A = np.arange(np.prod(shape)).reshape(shape)

        coefs = pywt.wavedec2(A, wavelet, mode='per', level=ll)
        # including 0th level as one
        u_ref = wv.structured_to_contiguous(coefs[:levels + 1])

        wavedec2, waverec2 = wv.daubechies_factory(shape, wavelet=wavelet)
        u = wavedec2(A, levels=levels)

        np.testing.assert_array_almost_equal(u_ref, u)
        return u
Esempio n. 2
0
    def _test_wavedec(self, wavelet, length, levels):
        import pywt
        ll = int(np.log2(length))
        A = np.arange(length)

        coefs = pywt.wavedec(A, wavelet, mode='per', level=ll)
        # including 0th level as one
        u_ref = wv.structured_to_contiguous(coefs[:levels + 1])

        wavedec, waverec = wv.daubechies_factory(length, wavelet=wavelet)
        u = wavedec(A, levels=levels)

        np.testing.assert_array_almost_equal(u_ref, u)
        return u
Esempio n. 3
0
    def _test_wavedec2(self, wavelet, shape, levels):
        import pywt

        ll = int(np.log2(max(shape)))
        A = np.arange(np.prod(shape)).reshape(shape)

        coefs = pywt.wavedec2(A, wavelet, mode="per", level=ll)
        # including 0th level as one
        u_ref = wv.structured_to_contiguous(coefs[: levels + 1])

        wavedec2, waverec2 = wv.daubechies_factory(shape, wavelet=wavelet)
        u = wavedec2(A, levels=levels)

        np.testing.assert_array_almost_equal(u_ref, u)
        return u
Esempio n. 4
0
    def _test_wavedec(self, wavelet, length, levels):
        import pywt

        ll = int(np.log2(length))
        A = np.arange(length)

        coefs = pywt.wavedec(A, wavelet, mode="per", level=ll)
        # including 0th level as one
        u_ref = wv.structured_to_contiguous(coefs[: levels + 1])

        wavedec, waverec = wv.daubechies_factory(length, wavelet=wavelet)
        u = wavedec(A, levels=levels)

        np.testing.assert_array_almost_equal(u_ref, u)
        return u
Esempio n. 5
0
    def _test_waverec(self, wavelet, length, levels):
        A = np.arange(length)
        ll = int(np.log2(length))

        N = 1 << levels
        # This assumes wavedec is working
        u = self._test_wavedec(wavelet, length, levels)

        u_zeros = np.zeros(len(u))
        u_zeros[:N] = u[:N]

        # Reconstruction
        wavedec, waverec = wv.daubechies_factory(length, wavelet=wavelet)

        A_rec_ref = waverec(u_zeros)
        A_rec = waverec(u)

        if levels == ll:
            np.testing.assert_array_almost_equal(A, A_rec)
        else:
            # They should not be equal, since the image will have lost
            # integrity
            assert not (A == A_rec).all()
            np.testing.assert_array_almost_equal(A_rec_ref, A_rec)
Esempio n. 6
0
    def _test_waverec2(self, wavelet, shape, levels):
        A = np.arange(np.prod(shape)).reshape(shape)
        ll = int(np.log2(max(shape)))

        N = 1 << levels
        # This assumes wavedec2 is working
        u = self._test_wavedec2(wavelet, shape, levels)

        u_zeros = np.zeros(u.shape)
        u_zeros[:N, :N] = u[:N, :N]

        # Reconstruction
        wavedec2, waverec2 = wv.daubechies_factory(A.shape, wavelet=wavelet)

        A_rec_ref = waverec2(u_zeros)
        A_rec = waverec2(u)

        if levels == ll:
            np.testing.assert_array_almost_equal(A, A_rec)
        else:
            # They should not be equal, since the image will have lost
            # integrity
            assert not (A == A_rec).all()
            np.testing.assert_array_almost_equal(A_rec_ref, A_rec)
Esempio n. 7
0
    def _test_waverec(self, wavelet, length, levels):
        A = np.arange(length)
        ll = int(np.log2(length))

        N = 1 << levels
        # This assumes wavedec is working
        u = self._test_wavedec(wavelet, length, levels)

        u_zeros = np.zeros(len(u))
        u_zeros[:N] = u[:N]

        # Reconstruction
        wavedec, waverec = wv.daubechies_factory(length, wavelet=wavelet)

        A_rec_ref = waverec(u_zeros)
        A_rec = waverec(u)

        if levels == ll:
            np.testing.assert_array_almost_equal(A, A_rec)
        else:
            # They should not be equal, since the image will have lost
            # integrity
            assert not (A == A_rec).all()
            np.testing.assert_array_almost_equal(A_rec_ref, A_rec)
Esempio n. 8
0
    def _test_waverec2(self, wavelet, shape, levels):
        A = np.arange(np.prod(shape)).reshape(shape)
        ll = int(np.log2(max(shape)))

        N = 1 << levels
        # This assumes wavedec2 is working
        u = self._test_wavedec2(wavelet, shape, levels)

        u_zeros = np.zeros(u.shape)
        u_zeros[:N, :N] = u[:N, :N]

        # Reconstruction
        wavedec2, waverec2 = wv.daubechies_factory(A.shape, wavelet=wavelet)

        A_rec_ref = waverec2(u_zeros)
        A_rec = waverec2(u)

        if levels == ll:
            np.testing.assert_array_almost_equal(A, A_rec)
        else:
            # They should not be equal, since the image will have lost
            # integrity
            assert not (A == A_rec).all()
            np.testing.assert_array_almost_equal(A_rec_ref, A_rec)
Esempio n. 9
0
 def _test_cache(self, shape, wavelet, levels):
     A = np.arange(np.prod(shape)).reshape(shape)
     wavedec2, waverec2 = wv.daubechies_factory(shape, wavelet)
     np.testing.assert_array_equal(wv.wavedec2(A, wavelet, levels),
                                   wavedec2(A, levels))
     np.testing.assert_array_equal(wv.waverec2(A, wavelet), waverec2(A))
Esempio n. 10
0
 def _test_cache(self, shape, wavelet, levels):
     A = np.arange(np.prod(shape)).reshape(shape)
     wavedec2, waverec2 = wv.daubechies_factory(shape, wavelet)
     np.testing.assert_array_equal(wv.wavedec2(A, wavelet, levels), wavedec2(A, levels))
     np.testing.assert_array_equal(wv.waverec2(A, wavelet), waverec2(A))