def test_daubechies_idaubechies(): f = luispedro_jpg(1) f = f[:256,:256] fo = f.copy() d = mahotas.daubechies(f, 'D8') r = mahotas.idaubechies(d, 'D8') assert np.mean( (r[4:-4,4:-4] - fo[4:-4,4:-4])**2) < 1.
def test_daubechies_idaubechies(): f = luispedro_jpg() f = f[:256, :256] fo = f.copy() d = mahotas.daubechies(f, 'D8') r = mahotas.idaubechies(d, 'D8') assert np.mean((r[4:-4, 4:-4] - fo[4:-4, 4:-4])**2) < 1.
def test_center_wavelet_iwavelet_decenter(): from mahotas import wavelet_center, wavelet_decenter import mahotas import numpy as np f = luispedro_jpg(1) f = f[:100,:250] fo = f.copy() for wav in ('D2', 'D4', 'D6', 'D8', 'D10', 'D12', 'D16'): fc = mahotas.wavelet_center(fo, border=24) t = mahotas.daubechies(fc, wav) r = mahotas.idaubechies(t, wav) rd = mahotas.wavelet_decenter(r, fo.shape, border=24) assert np.allclose(fo, rd)
def test_center_wavelet_iwavelet_decenter(): from mahotas import wavelet_center, wavelet_decenter import mahotas import numpy as np f = luispedro_jpg() f = f[:100, :250] fo = f.copy() for wav in ('D2', 'D4', 'D6', 'D8', 'D10', 'D12', 'D16'): fc = mahotas.wavelet_center(fo, border=24) t = mahotas.daubechies(fc, wav) r = mahotas.idaubechies(t, wav) rd = mahotas.wavelet_decenter(r, fo.shape, border=24) assert np.allclose(fo, rd)
direct = f[::2, ::2].copy() direct /= 8 direct = direct.astype(np.uint8) print("Fraction of zeros in original image (after division by 8):", np.mean(direct == 0)) plt.imshow(direct) # Transform using D8 Wavelet to obtain transformed image t: t = mahotas.daubechies(f, 'D8') plt.imshow(t) # Discard low-order bits: t /= 8 t = t.astype(np.int8) print("Fraction of zeros in transform (after division by 8):", np.mean(t == 0)) plt.imshow(t) # Let us look at what this looks like r = mahotas.idaubechies(t, 'D8') plt.imshow(r) # Go further, discard small values in the transformed space: tt = soft_threshold(t, 12) print( "Fraction of zeros in transform (after division by 8 & soft thresholding):", np.mean(tt == 0)) # Let us look again at what we have: rt = mahotas.idaubechies(tt, 'D8') plt.imshow(rt)
# A baseline compression method: save every other pixel and only high-order bits: direct = f[::2,::2].copy() direct /= 8 direct = direct.astype(np.uint8) print("Fraction of zeros in original image (after division by 8):", np.mean(direct==0)) plt.imshow(direct) # Transform using D8 Wavelet to obtain transformed image t: t = mahotas.daubechies(f,'D8') plt.imshow(t) # Discard low-order bits: t /= 8 t = t.astype(np.int8) print("Fraction of zeros in transform (after division by 8):", np.mean(t==0)) plt.imshow(t) # Let us look at what this looks like r = mahotas.idaubechies(t, 'D8') plt.imshow(r) # Go further, discard small values in the transformed space: tt = soft_threshold(t, 12) print("Fraction of zeros in transform (after division by 8 & soft thresholding):", np.mean(tt==0)) # Let us look again at what we have: rt = mahotas.idaubechies(tt, 'D8') plt.imshow(rt)