示例#1
0
def test_multilevel_recon_inverts_decomp(shape_setup, floating_dtype):
    """Test that reco is the inverse of decomp."""
    wavelet, pywt_mode, nlevels, image_shape, coeff_shapes = shape_setup

    image = np.random.uniform(size=image_shape).astype(floating_dtype)
    wave_decomp = pywt_multi_level_decomp(image, wavelet, nlevels, pywt_mode)
    wave_recon = pywt_multi_level_recon(wave_decomp, wavelet, pywt_mode,
                                        image_shape)
    assert wave_recon.shape == image.shape
    assert all_almost_equal(wave_recon, image)
示例#2
0
def test_multilevel_recon_inverts_decomp(shape_setup, floating_dtype):
    """Test that reco is the inverse of decomp."""
    wavelet, pywt_mode, nlevels, image_shape, coeff_shapes = shape_setup

    image = np.random.uniform(size=image_shape).astype(floating_dtype)
    wave_decomp = pywt_multi_level_decomp(image, wavelet, nlevels, pywt_mode)
    wave_recon = pywt_multi_level_recon(wave_decomp, wavelet, pywt_mode,
                                        image_shape)
    assert wave_recon.shape == image.shape
    assert all_almost_equal(wave_recon, image)
示例#3
0
文件: wavelet.py 项目: odlgroup/odl
 def _call(self, coeffs):
     """Return the inverse wavelet transform of ``coeffs``."""
     if self.impl == 'pywt':
         shapes = pywt_coeff_shapes(self.range.shape, self.pywt_wavelet,
                                    self.nlevels, self.pywt_pad_mode)
         coeff_list = pywt_coeffs_from_flat_array(coeffs, shapes)
         return pywt_multi_level_recon(
             coeff_list, recon_shape=self.range.shape,
             wavelet=self.pywt_wavelet, mode=self.pywt_pad_mode)
     else:
         raise RuntimeError("bad `impl` '{}'".format(self.impl))
示例#4
0
文件: wavelet.py 项目: yochju/odl
 def _call(self, coeffs):
     """Return the inverse wavelet transform of ``coeffs``."""
     if self.impl == 'pywt':
         shapes = pywt_coeff_shapes(self.range.shape, self.pywt_wavelet,
                                    self.nlevels, self.pywt_pad_mode)
         coeff_list = pywt_coeffs_from_flat_array(coeffs, shapes)
         return pywt_multi_level_recon(
             coeff_list, recon_shape=self.range.shape,
             wavelet=self.pywt_wavelet, mode=self.pywt_pad_mode)
     else:
         raise RuntimeError("bad `impl` '{}'".format(self.impl))
示例#5
0
def test_multilevel_decomp_inverts_recon(shape_setup):
    """Test that decomp is the inverse of recon."""
    dtype = 'float64'  # when fixed, use dtype fixture instead
    wavelet, pywt_mode, nlevels, image_shape, coeff_shapes = shape_setup

    if not ((ndim == 1 and wavelet == 'sym2' and pywt_mode == 'periodization')
            or (ndim == 1 and wavelet == 'db1'
                and pywt_mode in ('zero', 'periodization'))):
        # The reverse invertibility is not given since the wavelet
        # decomposition as implemented in PyWavelets, is not left-invertible.
        # Only some setups work by miracle.
        # TODO: investigate further
        pytest.xfail('not left-invertible')

    coeffs, _ = _grouped_and_flat_arrays(coeff_shapes, dtype)
    wave_recon = pywt_multi_level_recon(coeffs,
                                        wavelet,
                                        pywt_mode,
                                        recon_shape=image_shape)
    wave_decomp = pywt_multi_level_decomp(wave_recon, wavelet, nlevels,
                                          pywt_mode)
    assert all_almost_equal(coeffs, wave_decomp)
示例#6
0
def test_multilevel_decomp_inverts_recon(shape_setup):
    """Test that decomp is the inverse of recon."""
    dtype = 'float64'  # when fixed, use dtype fixture instead
    wavelet, pywt_mode, nlevels, image_shape, coeff_shapes = shape_setup

    if not ((ndim == 1 and
             wavelet == 'sym2' and
             pywt_mode == 'periodization') or
            (ndim == 1 and
             wavelet == 'db1' and
             pywt_mode in ('zero', 'periodization'))):
        # The reverse invertibility is not given since the wavelet
        # decomposition as implemented in PyWavelets, is not left-invertible.
        # Only some setups work by miracle.
        # TODO: investigate further
        pytest.xfail('not left-invertible')

    coeffs, _ = _grouped_and_flat_arrays(coeff_shapes, dtype)
    wave_recon = pywt_multi_level_recon(coeffs, wavelet, pywt_mode,
                                        recon_shape=image_shape)
    wave_decomp = pywt_multi_level_decomp(wave_recon, wavelet, nlevels,
                                          pywt_mode)
    assert all_almost_equal(coeffs, wave_decomp)