# 小波变换¶

```import numpy as np
import mahotas
import mahotas.demos

from mahotas.thresholding import soft_threshold
from matplotlib import pyplot as plt
from os import path
f = f[:256,:256]
plt.gray()
# Show the data:
print("Fraction of zeros in original image: {0}".format(np.mean(f==0)))
plt.imshow(f)
plt.show()
```

```direct = f[::2,::2].copy()
direct /= 8
direct = direct.astype(np.uint8)
print("Fraction of zeros in original image (after division by 8): {0}".format(np.mean(direct==0)))
plt.imshow(direct)
plt.show()
```

```# Transform using D8 Wavelet to obtain transformed image t:
t = mahotas.daubechies(f,'D8')

t /= 8
t = t.astype(np.int8)
print("Fraction of zeros in transform (after division by 8): {0}".format(np.mean(t==0)))
plt.imshow(t)
plt.show()
```

```# Let us look at what this looks like
r = mahotas.idaubechies(t, 'D8')
plt.imshow(r)
plt.show()
```

```tt = soft_threshold(t, 12)
print("Fraction of zeros in transform (after division by 8 & soft thresholding): {0}".format(np.mean(tt==0)))
# Let us look again at what we have:
rt = mahotas.idaubechies(tt, 'D8')
plt.imshow(rt)
```

## 那“边界”呢？¶

```fc = mahotas.wavelet_center(f)
t = mahotas.daubechies(fc, 'D8')
r = mahotas.idaubechies(fc, 'D8')
rd = mahotas.wavelet_decenter(r, fc.shape)
```

Now, `rd` is equal (except for rounding) to `fc` without any border effects.

## API文档¶

### 主要特征¶

mahotas.daubechies(f, code, inline=False)

Daubechies小波变换

fNdarray

2-D图像

code应力

‘D2’，‘D4’，...《D20》

inline布尔值，可选

`haar`

mahotas.haar(f, preserve_energy=True, inline=False)

f二维ndarray

preserve_energy布尔值，可选

inline布尔值，可选

`ihaar`

mahotas.idaubechies(f, code, inline=False)

Daubechies小波逆变换

fNdarray

2-D图像

code应力

‘D2’，‘D4’，...《D20》

inline布尔值，可选

`haar`

mahotas.ihaar(f, preserve_energy=True, inline=False)

`ihaar(haar(f))` 大致等于 `f` (相同，除非可能存在舍入问题)。

f二维ndarray

preserve_energy布尔值，可选

inline布尔值，可选

fNdarray

`haar`