Created
June 2, 2010 15:09
-
-
Save hoheinzollern/422483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void DWT::transform1d(float *src, int length, int step) | |
{ | |
float *tmp = new float[length]; | |
float W = 1/sqrt(2.0f); | |
for (int len = length/2; len >= PREVIEW; len /= 2) { | |
for (int i = 0; i < len; i++) { | |
float c = src[i*2*step]; | |
float w = src[(i*2+1)*step]; | |
tmp[i] = (c+w)*W; | |
tmp[i+len] = (c-w)*W; | |
} | |
for (int i = 0; i < len*2; i++) | |
src[i*step] = tmp[i]; | |
} | |
delete[] tmp; | |
} | |
void DWT::untransform1d(float *src, int length, int step) | |
{ | |
float *tmp = new float[length]; | |
float W = 1/sqrt(2.0f); | |
for (int len = PREVIEW; len < length; len *= 2) { | |
for (int i = 0; i < len; i++) { | |
float c = src[i*step]; | |
float w = src[(i+len)*step]; | |
tmp[i*2] = (c+w)*W; | |
tmp[i*2+1] = (c-w)*W; | |
} | |
for (int i = 0; i < len*2; i++) | |
src[i*step] = tmp[i]; | |
} | |
delete[] tmp; | |
} | |
void DWT::transform() | |
{ | |
for (int i = 0; i < height; i++) | |
transform1d(coeff + i * width, width, 1); | |
for (int i = 0; i < width; i++) | |
transform1d(coeff + i, height, width); | |
} | |
void DWT::untrasform() | |
{ | |
for (int i = 0; i < height; i++) | |
untransform1d(coeff + i * width, width, 1); | |
for (int i = 0; i < width; i++) | |
untransform1d(coeff + i, height, width); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment