3
import matplotlib.pyplot as plt
10
original = pywt.data.camera()
12
# Wavelet transform of image, and plot approximation and details
13
titles = ['Approximation', ' Horizontal detail',
14
'Vertical detail', 'Diagonal detail']
15
coeffs2 = pywt.dwt2(original, 'bior1.3')
16
LL, (LH, HL, HH) = coeffs2
18
for i, a in enumerate([LL, LH, HL, HH]):
19
ax = fig.add_subplot(2, 2, i + 1)
20
ax.imshow(a, interpolation="nearest", cmap=plt.cm.gray)
21
ax.set_title(titles[i], fontsize=12)
25
fig.suptitle("dwt2 coefficients", fontsize=14)
27
# Now reconstruct and plot the original image
28
reconstructed = pywt.idwt2(coeffs2, 'bior1.3')
30
plt.imshow(reconstructed, interpolation="nearest", cmap=plt.cm.gray)
32
# Check that reconstructed image is close to the original
33
np.testing.assert_allclose(original, reconstructed, atol=1e-13, rtol=1e-13)
36
# Now do the same with dwtn/idwtn, to show the difference in their signatures
38
coeffsn = pywt.dwtn(original, 'bior1.3')
40
for i, key in enumerate(['aa', 'ad', 'da', 'dd']):
41
ax = fig.add_subplot(2, 2, i + 1)
42
ax.imshow(coeffsn[key], interpolation="nearest", cmap=plt.cm.gray)
43
ax.set_title(titles[i], fontsize=12)
47
fig.suptitle("dwtn coefficients", fontsize=14)
49
# Now reconstruct and plot the original image
50
reconstructed = pywt.idwtn(coeffsn, 'bior1.3')
52
plt.imshow(reconstructed, interpolation="nearest", cmap=plt.cm.gray)
54
# Check that reconstructed image is close to the original
55
np.testing.assert_allclose(original, reconstructed, atol=1e-13, rtol=1e-13)