Public Member Functions | |
haarpoly () | |
void | forwardTrans (double[] vec) |
void | inverseTrans (double[] vec) |
Protected Member Functions | |
void | interp (double[] vec, int N, int direction) |
Static Package Attributes | |
static final int | numPts = 4 |
This wavelet transform extends the Haar transform with a polynomial wavelet function.
The polynomial wavelet uses 4-point polynomial interpolation to "predict" an odd point from four even point values.
This class extends the Haar transform with an interpolation stage which follows the predict and update stages of the Haar transform. The predict value is calculated from the even points, which in this case are the smoothed values calculated by the scaling function (e.g., the averages of the even and odd values).
The predict value is subtracted from the current odd value, which is the result of the Haar wavelet function (e.g., the difference between the odd value and the even value). This tends to result in large odd values after the interpolation stage, which is a weakness in this algorithm.
This algorithm was suggested by Wim Sweldens' tutorial Building Your Own Wavelets at Home.
http://www.bearcave.com/misl/misl_tech/wavelets/lifting/index.html
You may use this source code without limitation and without fee as long as you include: <blockquote> This software was written and is copyrighted by Ian Kaplan, Bear Products International, www.bearcave.com, 2001. </blockquote>
This software is provided "as is", without any warrenty or claim as to its usefulness. Anyone who uses this source code uses it at their own risk. Nor is any support provided by Ian Kaplan and Bear Products International.
Please send any bug fixes or suggested source changes to:
iank@bearcave.com
|
haarpoly class constructor
|
|
Haar transform extened with polynomial interpolation forward transform. This version of the forwardTrans function overrides the function in the liftbase base class. This function introduces an extra polynomial interpolation stage at the end of the transform. Reimplemented from lift::liftbase. 00209 { 00210 final int N = vec.length; 00211 00212 for (int n = N; n > 1; n = n >> 1) { 00213 split( vec, n ); 00214 predict( vec, n, forward ); 00215 update( vec, n, forward ); 00216 interp( vec, n, forward ); 00217 } // for 00218 } // forwardTrans
|
|
Predict an odd point from the even points, using 4-point polynomial interpolation. The four points used in the polynomial interpolation are the even points. We pretend that these four points are located at the x-coordinates 0,1,2,3. The first odd point interpolated will be located between the first and second even point, at 0.5. The next N-3 points are located at 1.5 (in the middle of the four points). The last two points are located at 2.5 and 3.5. For complete documentation see http://www.bearcave.com/misl/misl_tech/wavelets/lifting/index.html The difference between the predicted (interpolated) value and the actual odd value replaces the odd value in the forward transform. As the recursive steps proceed, N will eventually be 4 and then 2. When N = 4, linear interpolation is used. When N = 2, Haar interpolation is used (the prediction for the odd value is that it is equal to the even value).
00151 { 00152 int half = N >> 1; 00153 double d[] = new double[ numPts ]; 00154 00155 int k = 42; 00156 00157 for (int i = 0; i < half; i++) { 00158 double predictVal; 00159 00160 if (i == 0) { 00161 if (half == 1) { 00162 // e.g., N == 2, and we use Haar interpolation 00163 predictVal = vec[0]; 00164 } 00165 else { 00166 fill( vec, d, N, 0 ); 00167 predictVal = fourPt.interpPoint( 0.5, half, d ); 00168 } 00169 } 00170 else if (i == 1) { 00171 predictVal = fourPt.interpPoint( 1.5, half, d ); 00172 } 00173 else if (i == half-2) { 00174 predictVal = fourPt.interpPoint( 2.5, half, d ); 00175 } 00176 else if (i == half-1) { 00177 predictVal = fourPt.interpPoint( 3.5, half, d ); 00178 } 00179 else { 00180 fill( vec, d, N, i-1); 00181 predictVal = fourPt.interpPoint( 1.5, half, d ); 00182 } 00183 00184 int j = i + half; 00185 if (direction == forward) { 00186 vec[j] = vec[j] - predictVal; 00187 } 00188 else if (direction == inverse) { 00189 vec[j] = vec[j] + predictVal; 00190 } 00191 else { 00192 System.out.println("poly::predict: bad direction value"); 00193 } 00194 } 00195 } // interp
|
|
Haar transform extened with polynomial interpolation inverse transform. This version of the inverseTrans function overrides the function in the liftbase base class. This function introduces an inverse polynomial interpolation stage at the start of the inverse transform. Reimplemented from lift::liftbase. 00233 { 00234 final int N = vec.length; 00235 00236 for (int n = 2; n <= N; n = n << 1) { 00237 interp( vec, n, inverse ); 00238 update( vec, n, inverse ); 00239 predict( vec, n, inverse ); 00240 merge( vec, n ); 00241 } 00242 } // inverseTrans
|