File: mra2d.py

package info (click to toggle)
pywavelets 1.4.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,680 kB
  • sloc: python: 8,849; ansic: 5,134; makefile: 93
file content (40 lines) | stat: -rw-r--r-- 1,414 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python

import matplotlib.pyplot as plt

import pywt
import pywt.data

camera = pywt.data.camera()

wavelet = pywt.Wavelet('sym2')
level = 5
# Note: Running with transform="dwtn" is faster, but the resulting images will
#       look substantially worse.
coeffs = pywt.mran(camera, wavelet=wavelet, level=level, transform='swtn')
ca = coeffs[0]
details = coeffs[1:]

# Plot all coefficient subbands and the original
gridspec_kw = dict(hspace=0.1, wspace=0.1)
fontdict = dict(verticalalignment='center', horizontalalignment='center',
                color='k')
fig, axes = plt.subplots(len(details) + 1, 3, figsize=[5, 8], sharex=True,
                         sharey=True, gridspec_kw=gridspec_kw)
imshow_kw = dict(interpolation='nearest', cmap=plt.cm.gray)
for i, x in enumerate(details):
    axes[i][0].imshow(details[-i - 1]['ad'], **imshow_kw)

    axes[i][1].imshow(details[-i - 1]['da'], **imshow_kw)
    axes[i][2].imshow(details[-i - 1]['dd'], **imshow_kw)
    axes[i][0].text(256, 50, 'ad%d' % (i + 1), fontdict=fontdict)
    axes[i][1].text(256, 50, 'da%d' % (i + 1), fontdict=fontdict)
    axes[i][2].text(256, 50, 'dd%d' % (i + 1), fontdict=fontdict)

axes[-1][0].imshow(ca, **imshow_kw)
axes[-1][0].text(256, 50, 'approx.', fontdict=fontdict)
axes[-1][1].imshow(camera, **imshow_kw)
axes[-1][1].text(256, 50, 'original', fontdict=fontdict)

for ax in axes.ravel():
    ax.set_axis_off()