Wavelets in sage
There are no native wavelet packages in sage. But there is a great module in python that contains, among other things, forward and inverse discrete wavelet transforms (for one and two dimensions). It comes bundled with seventy-six wavelet filters, and allows support to build your own! The name is PyWavelets, written by Tariq Rashid, and can be retrieved from pypi.python.org/pypi/PyWavelets. In order to install it in sage, take the following steps:
- Download the latest version, and unpack it.
tar xvfz PyWavelets-0.2.0.tar.bz2
- Navigate to the top-level directory of the newly created PyWavelets folder, and install the package in sage.
/Applications/sage/sage -python setup.py install
- This should be enough! Open a sage session, and import the pywt module:
import pywt dir(pywt)
- It might happen that the installation is not very clean:
In that event, simply find where the _pywt.so library is in your PyWavelet package, and place a link in your sage libraries:
sudo ln -sv ./PyWavelets-0.2.0/build/lib.macosx-10.6-i386-2.6/pywt/_pywt.so /Applications/sage/local/lib/.
Once installed, you can get a flavor of what it means to work with this module by exploring a little. For example, to find out how many different families of wavelets are implemented, or the names of each of the filters present in the package, simply issue
To compute one level of the Haar-wavelet coefficients of a given image (the top level alone), we proceed as follows:
from numpy import * import scipy image=scipy.misc.lena().astype(float32) Aprox, Details = pywt.dwt2( image, pywt.Wavelet('haar') ) HorizDetail, VertDetail, DiagDetail = Details
|Vertical Detail||Diagonal Detail|
|Programming Python (See all Computer Programmer Books)||Ten Lectures on Wavelets (CBMS-NSF Regional Conference Series in Applied Mathematics) (See all Waves & Wave Mechanics Books)|