![](http://images-20200215.ebookreading.net/23/1/1/9781482247336/9781482247336__a-computational-introduction__9781482247336__bg1cd.png)
Wavelets 443
Python
In : h,g = rwt.daubcqf(2)
In : print rwt.dwt(v,h,1)[0]
[ 97.5807 35.3553 48.0833 22.6274 2.8284 -1.4142 2.8284 -2.8284]
In : print rwt.dwt(v,h,3)[0]
[ 101.8234 31.1127 44. 18. 2.8284 -1.4142 2.8284 -2.8284]
In : h = np.array([1,1]).astype(’float’)
In : vw = rwt.dwt(v,h,3)[0]
In : print vw[0]
[ 288. 88. 88. 36. 4. -2. 4. -4.]
In : hi = np.array([0.5,0.5]).astype(’float’)
In : print rwt.idwt(vw[0],hi,3)[0]
[ 71. 67. 24. 26. 36. 32. 14. 18.]
Let’s try an image. We shall apply the Haar wavelet to an image of size 256 × 256, first at
one scale. For display, it will be necessary to scale parts of the image for viewing.
MATLAB/Octave
>> c = imread(’cameraman.png’);
>> h = daubcqf(2)
>> cw1 = mdwt(double(c),h,1);
Now at this stage some adjustment needs to be done to display the transform. Because the
range of values in the transform
cw1 is large:
MATLAB/Octave
>> [max(cw1(:)),min(cw1(:))]
ans =
501.00 -209.50
some method will be needed to adjust those values for display. In MATLAB or Octave,
since
cw1 is an array of data type double, elements outside the range 0.0 − −1.0 will be
displayed as black or white. Adjustment can be done in several ways; first by simply using
mat2gray, second by a log function, as was done for the Fourier transform:
MATLAB/Octave
>> imshow(cw1)
>> figure, imshow(mat2gray(cw1))
>> cwlog = log(1+abs(cw1))
>> figure, imshow(mat2gray(cwlog))
In Python, this is more easily done as images are automatically scaled for display:
Python
In : h,g = rwt.daubcqf(2)
In : cw1 = rwt.dwt(castype(’float’),h,1)[0]
In : cwlog = np.log(1+abs(cw1))
and both cw1 and cwlog can be displayed simply with io.imshow. All three images are
shown in Figure 15.6. Now consider the same transform, but at 3 scales: