pywt

Форк
0
/
dwt2_dwtn_image.py 
58 строк · 1.7 Кб
1
#!/usr/bin/env python
2

3
import matplotlib.pyplot as plt
4
import numpy as np
5

6
import pywt
7
import pywt.data
8

9
# Load image
10
original = pywt.data.camera()
11

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
17
fig = plt.figure()
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)
22
    ax.set_xticks([])
23
    ax.set_yticks([])
24

25
fig.suptitle("dwt2 coefficients", fontsize=14)
26

27
# Now reconstruct and plot the original image
28
reconstructed = pywt.idwt2(coeffs2, 'bior1.3')
29
fig = plt.figure()
30
plt.imshow(reconstructed, interpolation="nearest", cmap=plt.cm.gray)
31

32
# Check that reconstructed image is close to the original
33
np.testing.assert_allclose(original, reconstructed, atol=1e-13, rtol=1e-13)
34

35

36
# Now do the same with dwtn/idwtn, to show the difference in their signatures
37

38
coeffsn = pywt.dwtn(original, 'bior1.3')
39
fig = plt.figure()
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)
44
    ax.set_xticks([])
45
    ax.set_yticks([])
46

47
fig.suptitle("dwtn coefficients", fontsize=14)
48

49
# Now reconstruct and plot the original image
50
reconstructed = pywt.idwtn(coeffsn, 'bior1.3')
51
fig = plt.figure()
52
plt.imshow(reconstructed, interpolation="nearest", cmap=plt.cm.gray)
53

54
# Check that reconstructed image is close to the original
55
np.testing.assert_allclose(original, reconstructed, atol=1e-13, rtol=1e-13)
56

57

58
plt.show()
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.