00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <it/io.h>
00023 #include <it/mat.h>
00024 #include <it/transform.h>
00025 #include <it/wavelet.h>
00026 #include <it/transform2D.h>
00027 #include <it/wavelet2D.h>
00028 #include <it/separable2D.h>
00029
00030
00031 it_function (rescale_image)
00032 {
00033 x += 128;
00034 if (x < 0)
00035 x = 0;
00036 if (x > 255)
00037 x = 255;
00038
00039 return (x);
00040 }
00041
00042
00043 it_function (rescale_sound)
00044 {
00045 x *= 1. / 32;
00046
00047 return (x);
00048 }
00049
00050 int main ()
00051 {
00052 it_wavelet_t *wavelet;
00053 it_wavelet2D_t *wavelet2D;
00054 it_separable2D_t *separable;
00055 const char *image_in = "../data/test.pgm";
00056 const char *image_out = "out.pgm";
00057 const char *sound_in = "../data/test.wav";
00058 const char *sound_out = "out.wav";
00059 char pnm_type, comments[1000];
00060 int width, height, maxval;
00061 int levels;
00062 int length, channels, srate, depth;
00063 mat m, mt;
00064 vec v, vt;
00065
00066 levels = 4;
00067
00068
00069 if (!wav_info (sound_in, &channels, &srate, &depth, &length)) {
00070 fprintf (stderr, "unable to open file %s\n", sound_in);
00071 return (1);
00072 }
00073 printf
00074 ("file name = %s\nchannels = %d\nsampling rate = %d\ndepth = %d\nlength = %d samples/channel\n",
00075 sound_in, channels, srate, depth, length);
00076
00077 m = mat_wav_read (sound_in);
00078 v = m[0];
00079
00080
00081 vt = it_dwt (v, it_wavelet_lifting_53, levels);
00082 vec_delete (v);
00083
00084
00085 v = vec_new_eval (vt, rescale_sound, NULL);
00086 m[0] = v;
00087 mat_wav_write ("wavelet.wav", m, srate, depth);
00088 vec_delete (v);
00089
00090
00091 v = it_idwt (vt, it_wavelet_lifting_53, levels);
00092 vec_delete (vt);
00093
00094 m[0] = v;
00095 mat_wav_write (sound_out, m, srate, depth);
00096 mat_delete (m);
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 m = mat_pgm_read (image_in);
00115 printf ("PGM %dx%d\n", mat_height (m), mat_width (m));
00116
00117 levels = 1;
00118
00119
00120 wavelet = it_wavelet_new (it_wavelet_lifting_97, levels);
00121
00122 separable = it_separable2D_new (wavelet);
00123
00124
00125 mt = (mat) it_transform2D (separable, m);
00126 mat_delete (m);
00127
00128
00129 m = mat_new_eval (mt, rescale_image, NULL);
00130 mat_pgm_write ("wavelet_separable.pgm", m);
00131 mat_delete (m);
00132
00133
00134 m = (mat) it_itransform2D (separable, mt);
00135 mat_delete (mt);
00136
00137 it_delete (separable);
00138 it_delete (wavelet);
00139
00140 mat_pgm_write ("separable.pgm", m);
00141 mat_delete (m);
00142
00143
00144 pnm_info (image_in, &pnm_type, &width, &height, &maxval, comments, 1000);
00145 printf ("file name = %s\npnm type = %c\n%dx%d -> maxval=%d\ncomments=%s\n",
00146 image_in, pnm_type, width, height, maxval, "");
00147
00148 m = mat_pgm_read (image_in);
00149
00150 printf
00151 ("height(m) = %d\tmaxheight(m) = %d\nwidth(m) = %d\tmaxwidth(m) = %d\n",
00152 mat_height (m), mat_height_max (m), mat_width (m), mat_width_max (m));
00153
00154 levels = 5;
00155
00156
00157 wavelet2D = it_wavelet2D_new (it_wavelet_lifting_97, levels);
00158
00159
00160 mt = it_wavelet2D_transform (wavelet2D, m);
00161 mat_delete (m);
00162
00163
00164 m = mat_new_eval (mt, rescale_image, NULL);
00165 mat_pgm_write ("wavelet.pgm", m);
00166 mat_delete (m);
00167
00168
00169 m = it_wavelet2D_itransform (wavelet2D, mt);
00170 mat_delete (mt);
00171
00172 it_delete (wavelet2D);
00173
00174 mat_pgm_write (image_out, m);
00175 mat_delete (m);
00176
00177 return 0;
00178 }