⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ofilter2.c

📁 LastWave
💻 C
📖 第 1 页 / 共 2 页
字号:
static void InitOFilter2(OFILTER2 filter, int filterSize, int filterFirst, LWFLOAT *data){  int i;  filter->size = filterSize;  filter->firstIndex = filterFirst;  filter->center = -filter->firstIndex;  filter->coeff = FloatAlloc(filter->size);  if (data != NULL) {    for (i = 0; i < filter->size; i++) filter->coeff[i] = data[i];  } else {    for (i = 0; i < filter->size; i++) filter->coeff[i] = 0;  }}static void CopyOFilter2(OFILTER2 in,OFILTER2 out){  if (out->coeff != NULL) Free(out->coeff);  InitOFilter2(out,in->size,in->firstIndex,in->coeff);}static void DeleteOFilter2(OFILTER2 filter){  if (filter->coeff != NULL) Free(filter->coeff);  Free(filter);}      /************************************************* * * Function that deals with OFilterSet structures * *************************************************/static OFILTERSET NewOFilterSet(void){  OFILTERSET filter;    filter = (OFILTERSET) Malloc(sizeof(OFilterSet));    filter->symmetric = NO;  filter->analysisLow = filter->analysisHigh = filter->synthesisLow = filter->synthesisHigh = NULL;    return(filter);}static void InitOFilterSet (OFILTERSET filterset, int symmetric,LWFLOAT *anLow, int anLowSize, int anLowFirst,  	                       LWFLOAT *synLow, int synLowSize, int synLowFirst){  int i, sign;  filterset->symmetric = symmetric;  filterset->analysisLow = NewOFilter2();  InitOFilter2(filterset->analysisLow,anLowSize, anLowFirst, anLow);  /* If no synthesis coeffs are given, assume wavelet is orthogonal */  if (synLow == NULL)  {    filterset->synthesisLow = NewOFilter2();    CopyOFilter2(filterset->analysisLow,filterset->synthesisLow);    /* For orthogonal wavelets, compute the high pass filter using     the relation g_n = (-1)^n h_{1-n}^*     (or equivalently g_{1-n} = (-1)^{1-n} h_n^*) */    filterset->analysisHigh = NewOFilter2();    InitOFilter2(filterset->analysisHigh,filterset->analysisLow->size, 2 - filterset->analysisLow->size -				filterset->analysisLow->firstIndex,NULL);          /* Compute (-1)^(1-n) for first n */    if (filterset->analysisLow->firstIndex % 2) sign = 1;    else sign = -1;        for (i = 0; i < filterset->analysisLow->size; i++)  {      filterset->analysisHigh->coeff[1 - i - filterset->analysisLow->firstIndex - 		                             filterset->analysisHigh->firstIndex] = 	       sign * filterset->analysisLow->coeff[i];      sign *= -1;    }    /* Copy the high pass analysis filter to the synthesis filter */    filterset->synthesisHigh = NewOFilter2();    CopyOFilter2(filterset->analysisHigh,filterset->synthesisHigh);      } else {      /* If separate synthesis coeffs given, assume biorthogonal */        filterset->synthesisLow = NewOFilter2();    InitOFilter2(filterset->synthesisLow,synLowSize, synLowFirst, synLow);    /* For orthogonal wavelets, compute the high frequency filter using     the relation g_n = (-1)^n complement (h~_{1-n}) and                  g~_n = (-1)^n complement (h_{1-n})     (or equivalently g_{1-n} = (-1)^{1-n} complement (h~_n)) */        filterset->analysisHigh = NewOFilter2();    InitOFilter2(filterset->analysisHigh,filterset->synthesisLow->size, 2 - filterset->synthesisLow->size -			      filterset->synthesisLow->firstIndex,NULL);        /* Compute (-1)^(1-n) for first n */    if (filterset->synthesisLow->firstIndex % 2) sign = 1;    else sign = -1;        for (i = 0; i < filterset->synthesisLow->size; i++)  {      filterset->analysisHigh->coeff[1 - i - filterset->synthesisLow->firstIndex -			                         filterset->analysisHigh->firstIndex] = 	      sign * filterset->synthesisLow->coeff[i];      sign *= -1;    }    filterset->synthesisHigh = NewOFilter2();    InitOFilter2(filterset->synthesisHigh,filterset->analysisLow->size, 2 - filterset->analysisLow->size -			    filterset->analysisLow->firstIndex,NULL);     /* Compute (-1)^(1-n) for first n */    if (filterset->analysisLow->firstIndex % 2) sign = 1;    else sign = -1;    for (i = 0; i < filterset->analysisLow->size; i++)  {      filterset->synthesisHigh->coeff[1 - i - filterset->analysisLow->firstIndex -			                          filterset->synthesisHigh->firstIndex] = 	     sign * filterset->analysisLow->coeff[i];      sign *= -1;    }  }}static void CopyOFilterSet (OFILTERSET in, OFILTERSET out){  out->symmetric = in->symmetric;  CopyOFilter2(in->analysisLow,out->analysisLow);  CopyOFilter2(in->analysisHigh,out->analysisHigh);  CopyOFilter2(in->synthesisLow,out->synthesisLow);  CopyOFilter2(in->synthesisHigh,out->synthesisHigh);} static void DeleteOFilterSet(OFILTERSET filter)  {  DeleteOFilter2(filter->analysisLow);  DeleteOFilter2(filter->analysisHigh);  DeleteOFilter2(filter->synthesisLow);  DeleteOFilter2(filter->synthesisHigh);}          /******************************************** * * Initializing the different OFilterSets * ********************************************/static OFILTERSET Haar = NULL;static OFILTERSET Daub4, Daub6, Daub8, Antonini, Villa, Adelson,                  Brislawn, Brislawn2, Villa1, Villa2, Villa3, Villa4, Villa5, Villa6, Odegard;static void InitOFilters2d(void){  Haar = NewOFilterSet();  InitOFilterSet (Haar,NO,HaarCoeffs,2,0,NULL,0,0);  Daub4 = NewOFilterSet();  InitOFilterSet (Daub4,NO,Daub4Coeffs,4,0,NULL,0,0);  Daub6 = NewOFilterSet();  InitOFilterSet (Daub6,NO,Daub6Coeffs,6,0,NULL,0,0);  Daub8 = NewOFilterSet();  InitOFilterSet (Daub8,NO,Daub8Coeffs,8,0,NULL,0,0);  Antonini = NewOFilterSet();  InitOFilterSet (Antonini,YES,AntoniniAnalysis,9,-4,AntoniniSynthesis,7,-3);  Villa = NewOFilterSet();  InitOFilterSet (Villa,YES,Villa1810Analysis,10,-4,Villa1810Synthesis,18,-8);  Adelson = NewOFilterSet();  InitOFilterSet (Adelson,YES,AdelsonCoeffs,9,-4,NULL,0,0);  Brislawn = NewOFilterSet();  InitOFilterSet (Brislawn,YES,BrislawnAnalysis,9,-4,BrislawnSynthesis,9,-3);  Brislawn2 = NewOFilterSet();  InitOFilterSet (Brislawn2,YES,Brislawn2Analysis,10,-4,Brislawn2Synthesis,10,-4);    Villa1 = NewOFilterSet();  InitOFilterSet (Villa1,YES,Villa1Analysis,9,-4,Villa1Synthesis,7,-3);  Villa2 = NewOFilterSet();  InitOFilterSet (Villa2,YES,Villa2Analysis,13,-6,Villa2Synthesis,11,-5);  Villa3 = NewOFilterSet();  InitOFilterSet (Villa3,YES,Villa3Analysis,6,-2,Villa3Synthesis,10,-4);  Villa4 = NewOFilterSet();  InitOFilterSet (Villa4,YES,Villa4Analysis,5,-2,Villa4Synthesis,3,-1);  Villa5 = NewOFilterSet();  InitOFilterSet (Villa5,YES,Villa5Analysis,2,0,Villa5Synthesis,6,-2);  Villa6 = NewOFilterSet();  InitOFilterSet (Villa6,YES,Villa6Analysis,9,-4,Villa6Synthesis,3,-1);  Odegard = NewOFilterSet();  InitOFilterSet (Odegard,YES,OdegardAnalysis,9,-4,OdegardSynthesis,7,-3);  }/*************************************************** * * Functions that deal with OWavelet2 structures * ***************************************************/char defaultO2WaveletName[40];/* * Just copy the fields of a filterset into a wavelet */static void LazycopyOWavelet2 (OFILTERSET filterset,OWAVELET2 w){   w->symmetric = filterset->symmetric;  w->analysisLow =filterset->analysisLow;  w->analysisHigh = filterset->analysisHigh;  w->synthesisLow = filterset->synthesisLow;  w->synthesisHigh = filterset->synthesisHigh;}/* * Create a new wavelet from a filter set name */OWAVELET2  NewOWavelet2(char * nameFilterset){  OWAVELET2 w;     if (Haar == NULL)  InitOFilters2d();      w = (OWAVELET2) Malloc(sizeof(struct owavelet2));    if (!strcmp(nameFilterset,"Haar")) LazycopyOWavelet2(Haar,w);  else if (!strcmp(nameFilterset,"Daub4")) LazycopyOWavelet2(Daub4,w);  else if (!strcmp(nameFilterset,"Daub6")) LazycopyOWavelet2(Daub6,w);  else if (!strcmp(nameFilterset,"Daub8")) LazycopyOWavelet2(Daub8,w);  else if (!strcmp(nameFilterset,"Antonini")) LazycopyOWavelet2(Antonini,w);  else if (!strcmp(nameFilterset,"Villa")) LazycopyOWavelet2(Villa,w);  else if (!strcmp(nameFilterset,"Adelson")) LazycopyOWavelet2(Adelson,w);  else if (!strcmp(nameFilterset,"Brislawn")) LazycopyOWavelet2(Brislawn,w);  else if (!strcmp(nameFilterset,"Brislawn2")) LazycopyOWavelet2(Brislawn2,w);  else if (!strcmp(nameFilterset,"Villa1")) LazycopyOWavelet2(Villa1,w);  else if (!strcmp(nameFilterset,"Villa2")) LazycopyOWavelet2(Villa2,w);  else if (!strcmp(nameFilterset,"Villa3")) LazycopyOWavelet2(Villa3,w);  else if (!strcmp(nameFilterset,"Villa4")) LazycopyOWavelet2(Villa4,w);  else if (!strcmp(nameFilterset,"Villa5")) LazycopyOWavelet2(Villa5,w);  else if (!strcmp(nameFilterset,"Villa6")) LazycopyOWavelet2(Villa6,w);  else if (!strcmp(nameFilterset,"Odegard")) LazycopyOWavelet2(Odegard,w);  else Errorf("NewOWavelet2() : Unknown name of wavelet");       /* amount of space to leave for padding vectors for symmetric extensions */  w->npad = MAX(w->analysisLow->size, w->analysisHigh->size);    strcpy(w->name,nameFilterset);    return(w);}/* * Delete a wavelet  */void DeleteOWavelet2(OWAVELET2 w){  Free(w);}/* Setting the default wavelet */void OWt2f(char *str){  OWAVELET2 w;  w = NewOWavelet2(str);  DeleteOWavelet2(w);    strncpy(defaultO2WaveletName,str,15);  defaultO2WaveletName[14] = '\0';}void C_OWt2f (char **argv){  char *str;    if (*argv == NULL) {    SetResultStr(defaultO2WaveletName);    return;  }    argv = ParseArgv(argv,tSTR,&str,0);   OWt2f(str);    }void InitOWavelet2(void){  strcpy(defaultO2WaveletName,"Haar");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -