| 1 |
|
| 2 |
|
| 3 |
import matplotlib.pyplot as plt |
| 4 |
|
| 5 |
import pywt |
| 6 |
import pywt.data |
| 7 |
|
| 8 |
camera = pywt.data.camera() |
| 9 |
|
| 10 |
wavelet = pywt.Wavelet('sym2') |
| 11 |
level = 5 |
| 12 |
|
| 13 |
|
| 14 |
coeffs = pywt.mran(camera, wavelet=wavelet, level=level, transform='swtn') |
| 15 |
ca = coeffs[0] |
| 16 |
details = coeffs[1:] |
| 17 |
|
| 18 |
|
| 19 |
gridspec_kw = dict(hspace=0.1, wspace=0.1) |
| 20 |
fontdict = dict(verticalalignment='center', horizontalalignment='center', |
| 21 |
color='k') |
| 22 |
fig, axes = plt.subplots(len(details) + 1, 3, figsize=[5, 8], sharex=True, |
| 23 |
sharey=True, gridspec_kw=gridspec_kw) |
| 24 |
imshow_kw = dict(interpolation='nearest', cmap=plt.cm.gray) |
| 25 |
for i, x in enumerate(details): |
| 26 |
axes[i][0].imshow(details[-i - 1]['ad'], **imshow_kw) |
| 27 |
|
| 28 |
axes[i][1].imshow(details[-i - 1]['da'], **imshow_kw) |
| 29 |
axes[i][2].imshow(details[-i - 1]['dd'], **imshow_kw) |
| 30 |
axes[i][0].text(256, 50, 'ad%d' % (i + 1), fontdict=fontdict) |
| 31 |
axes[i][1].text(256, 50, 'da%d' % (i + 1), fontdict=fontdict) |
| 32 |
axes[i][2].text(256, 50, 'dd%d' % (i + 1), fontdict=fontdict) |
| 33 |
|
| 34 |
axes[-1][0].imshow(ca, **imshow_kw) |
| 35 |
axes[-1][0].text(256, 50, 'approx.', fontdict=fontdict) |
| 36 |
axes[-1][1].imshow(camera, **imshow_kw) |
| 37 |
axes[-1][1].text(256, 50, 'original', fontdict=fontdict) |
| 38 |
|
| 39 |
for ax in axes.ravel(): |
| 40 |
ax.set_axis_off() |