Coding wavelets the easy way

Nonlinear Approximation



Given an number Nelem, the wavelet nonlinear approximation keeps the Nelem details with largest amplitude (in absolute value) and sets the other to zero.

In the 1D case, we determine the threshold by sorting the details. Here things are more complicated because each Details{i} is itself as structure consisting in three image structures. Therefore it is worthwhile to write a dedicated routine
function det = vectorize2D(WT)
that reshapes and concatenates all detail coefficients into a line vector. See the documentation on the reshape and numel Matlab commands.

Once this is done, you can use the routine in the following one
function t = thresholdValue2D(WT,numEl)
which actually computes the threshold t to keep numEl detail coefficients in the wavelet transform WT.

Since we will threshold images and not vectors, we have to write
function y = thresholdMatrix(x,t)
which applies the threshold t to the matrix x vector by vector. This because the find Matlab function is cumbersome to use on arrays, so it is simpler to use it on a column by column basis.

Next write
function WT = threshold2D(WT,t)
that applies the threshold t on the 2D wavelet transform WT. This needs a rewrite because WT.Details{i} is a 3-field structure now. On each detail image you will call thresholdMatrix.