Coding wavelets the easy way

Grayscale Approximation



You will now write a function
function g = grayWaveletCompress(grayImage,WaveletOrder,scale,ratio)
that performs a nonlinear approximation on a grayscale image grayImage, using the filters stored in the Daubn.mat file (n being the value of WaveletOrder), at scale scale and where ratio is the ratio of detail coefficients that are kept, i.e. not set to zero in the threshold procedure. For simplicity's sake, the image will be supposed to be 512x512, since this is the case for our two examples.
Do not forget to trim the columns and rows after the reconstruction to obtain an image whose pixel coordinates correspond to the pixel coordinates of the original image.
The output must be of type uint8.

For general image, a simple procedure consists in computing the maximum logarithm in base 2 of the image dimensions; let N this dimensions. Then you pad the image with dark pixels (R=G=B=0) to obtain an image of size 2^Nx2^N. This way you can process the luminance and chrominance channels up to scale N.

The Daubechies filters are available online: Daub2.mat, Daub4.mat, Daub6.mat, Daub8.mat, Daub10.mat, Daub12.mat, Daub14.mat, Daub16.mat, Daub18.mat and Daub20.mat.
WaveletOrder is not really the order of the filters, but their length. The d field for the reconstruction filters should be set to 0 for the h and g filters, and to WaveletOrder-1 for the reconstruction filters rh and rg.

The color compression routine that we will see next is similar except that it works on two channels.