wt2 examples added

This commit is contained in:
Rafat Hussain 2019-04-06 08:39:01 +05:30
parent 8580e896da
commit 2ef5c81d82
5 changed files with 269 additions and 2 deletions

View File

@ -4250,7 +4250,7 @@ void wt2_summary(wt2_object wt) {
t += 1;
printf("Vertical Coefficients access at wt->coeffaccess[%d]=%d, Vector size:%d \n", t, wt->coeffaccess[t], vsize);
t += 1;
printf("Detail Coefficients access at wt->coeffaccess[%d]=%d, Vector size:%d \n\n", t, wt->coeffaccess[t], vsize);
printf("Diagonal Coefficients access at wt->coeffaccess[%d]=%d, Vector size:%d \n\n", t, wt->coeffaccess[t], vsize);
}
}

View File

@ -30,6 +30,18 @@ add_executable(modwtdenoisetest modwtdenoisetest.c)
target_link_libraries(modwtdenoisetest wauxlib wavelib)
add_executable(dwt2test dwt2test.c)
target_link_libraries(dwt2test wavelib)
add_executable(swt2test swt2test.c)
target_link_libraries(swt2test wavelib)
add_executable(modwt2test modwt2test.c)
target_link_libraries(modwt2test wavelib)
if(UNIX)
target_link_libraries(cwttest m)
target_link_libraries(dwttest m)
@ -39,9 +51,12 @@ if(UNIX)
target_link_libraries(wtreetest m)
target_link_libraries(denoisetest m)
target_link_libraries(modwtdenoisetest m)
target_link_libraries(dwt2test m)
target_link_libraries(swt2test m)
target_link_libraries(modwt2test m)
endif()
set_target_properties(cwttest dwttest swttest modwttest dwpttest wtreetest denoisetest modwtdenoisetest
set_target_properties(cwttest dwttest swttest modwttest dwpttest wtreetest denoisetest modwtdenoisetest dwt2test swt2test modwt2test
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
)

87
test/dwt2test.c Executable file
View File

@ -0,0 +1,87 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "../header/wavelib.h"
double absmax(double *array, int N) {
double max;
int i;
max = 0.0;
for (i = 0; i < N; ++i) {
if (fabs(array[i]) >= max) {
max = fabs(array[i]);
}
}
return max;
}
double generate_rnd() {
double rnd;
rnd = (double) (rand() % 100 + 1);
return rnd;
}
int main() {
wave_object obj;
wt2_object wt;
int i, k, J, rows, cols,N;
double *inp, *wavecoeffs,*oup,*diff;
double *cLL;
int ir, ic;
double amax;
rows = 32;
cols = 30;
N = rows*cols;
char *name = "db2";
obj = wave_init(name);// Initialize the wavelet
srand(time(0));
inp = (double*)calloc(N, sizeof(double));
oup = (double*)calloc(N, sizeof(double));
diff = (double*)calloc(N, sizeof(double));
J = 3;
wt = wt2_init(obj, "dwt", rows,cols, J);
for (i = 0; i < rows; ++i) {
for (k = 0; k < cols; ++k) {
//inp[i*cols + k] = i*cols + k;
inp[i*cols + k] = generate_rnd();
oup[i*cols + k] = 0.0;
}
}
wavecoeffs = dwt2(wt, inp);
cLL = getWT2Coeffs(wt, wavecoeffs, 1, "D", &ir, &ic);
dispWT2Coeffs(cLL, ir, ic);
idwt2(wt, wavecoeffs, oup);
for (i = 0; i < rows*cols; ++i) {
diff[i] = oup[i] - inp[i];
}
amax = absmax(diff, rows*cols);
wt2_summary(wt);
printf("Abs Max %g \n", amax);
wave_free(obj);
wt2_free(wt);
free(inp);
free(wavecoeffs);
free(oup);
free(diff);
return 0;
}

82
test/modwt2test.c Executable file
View File

@ -0,0 +1,82 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "../header/wavelib.h"
double absmax(double *array, int N) {
double max;
int i;
max = 0.0;
for (i = 0; i < N; ++i) {
if (fabs(array[i]) >= max) {
max = fabs(array[i]);
}
}
return max;
}
double generate_rnd() {
double rnd;
rnd = (double) (rand() % 100 + 1);
return rnd;
}
int main() {
wave_object obj;
wt2_object wt;
int i, k, J, rows, cols,N,ir,ic;
double *inp, *wavecoeffs, *oup,*cLL,*diff;
double amax;
rows = 51;
cols = 40;
N = rows*cols;
char *name = "db2";
obj = wave_init(name);// Initialize the wavelet
inp = (double*)calloc(N, sizeof(double));
oup = (double*)calloc(N, sizeof(double));
diff = (double*)calloc(N, sizeof(double));
J = 2;
wt = wt2_init(obj, "modwt", rows, cols, J);
for (i = 0; i < rows; ++i) {
for (k = 0; k < cols; ++k) {
//inp[i*cols + k] = i*cols + k;
inp[i*cols + k] = generate_rnd();
oup[i*cols + k] = 0.0;
}
}
wavecoeffs = modwt2(wt, inp);
cLL = getWT2Coeffs(wt, wavecoeffs, J, "A", &ir, &ic);
//dispWT2Coeffs(cLL, ir, ic);
imodwt2(wt, wavecoeffs, oup);
for (i = 0; i < N; ++i) {
diff[i] = oup[i] - inp[i];
}
amax = absmax(diff, N);
wt2_summary(wt);
printf("Abs Max %g \n", amax);
wave_free(obj);
wt2_free(wt);
free(inp);
free(wavecoeffs);
free(oup);
free(diff);
return 0;
}

83
test/swt2test.c Executable file
View File

@ -0,0 +1,83 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "../header/wavelib.h"
double absmax(double *array, int N) {
double max;
int i;
max = 0.0;
for (i = 0; i < N; ++i) {
if (fabs(array[i]) >= max) {
max = fabs(array[i]);
}
}
return max;
}
double generate_rnd() {
double rnd;
rnd = (double) (rand() % 100 + 1);
return rnd;
}
int main() {
wave_object obj;
wt2_object wt;
int i, k, J, rows, cols;
double *inp, *wavecoeffs, *oup, *cLL,*diff;
double amax;
int ir, ic, N;
rows = 64;
cols = 48;
char *name = "bior3.1";
obj = wave_init(name);// Initialize the wavelet
N = rows*cols;
inp = (double*)calloc(N, sizeof(double));
oup = (double*)calloc(N, sizeof(double));
diff = (double*)calloc(N, sizeof(double));
J = 2;
wt = wt2_init(obj, "swt", rows, cols, J);
for (i = 0; i < rows; ++i) {
for (k = 0; k < cols; ++k) {
//inp[i*cols + k] = i*cols + k;
inp[i*cols + k] = generate_rnd();
oup[i*cols + k] = 0.0;
}
}
wavecoeffs = swt2(wt, inp);
cLL = getWT2Coeffs(wt, wavecoeffs, J, "A", &ir, &ic);
dispWT2Coeffs(cLL, ir, ic);
iswt2(wt, wavecoeffs, oup);
for (i = 0; i < N; ++i) {
diff[i] = oup[i] - inp[i];
}
amax = absmax(diff, N);
wt2_summary(wt);
printf("Abs Max %g \n", amax);
wave_free(obj);
wt2_free(wt);
free(inp);
free(wavecoeffs);
free(oup);
free(diff);
return 0;
}