| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
import numpy as np |
| 5 |
import matplotlib.pyplot as plt |
| 6 |
|
| 7 |
from pywt import WaveletPacket2D |
| 8 |
import pywt.data |
| 9 |
|
| 10 |
|
| 11 |
arr = pywt.data.aero() |
| 12 |
|
| 13 |
wp2 = WaveletPacket2D(arr, 'db2', 'symmetric', maxlevel=2) |
| 14 |
|
| 15 |
|
| 16 |
plt.imshow(arr, interpolation="nearest", cmap=plt.cm.gray) |
| 17 |
|
| 18 |
path = ['d', 'v', 'h', 'a'] |
| 19 |
|
| 20 |
|
| 21 |
fig = plt.figure() |
| 22 |
for i, p2 in enumerate(path): |
| 23 |
ax = fig.add_subplot(2, 2, i + 1) |
| 24 |
ax.imshow(np.sqrt(np.abs(wp2[p2].data)), origin='upper', |
| 25 |
interpolation="nearest", cmap=plt.cm.gray) |
| 26 |
ax.set_title(p2) |
| 27 |
|
| 28 |
|
| 29 |
for p1 in path: |
| 30 |
fig = plt.figure() |
| 31 |
for i, p2 in enumerate(path): |
| 32 |
ax = fig.add_subplot(2, 2, i + 1) |
| 33 |
p1p2 = p1 + p2 |
| 34 |
ax.imshow(np.sqrt(np.abs(wp2[p1p2].data)), origin='upper', |
| 35 |
interpolation="nearest", cmap=plt.cm.gray) |
| 36 |
ax.set_title(p1p2) |
| 37 |
|
| 38 |
fig = plt.figure() |
| 39 |
i = 1 |
| 40 |
for row in wp2.get_level(2, 'freq'): |
| 41 |
for node in row: |
| 42 |
ax = fig.add_subplot(len(row), len(row), i) |
| 43 |
ax.set_title("%s=(%s row, %s col)" % ( |
| 44 |
(node.path,) + wp2.expand_2d_path(node.path))) |
| 45 |
ax.imshow(np.sqrt(np.abs(node.data)), origin='upper', |
| 46 |
interpolation="nearest", cmap=plt.cm.gray) |
| 47 |
i += 1 |
| 48 |
|
| 49 |
plt.show() |