📄 filter.c
字号:
filter->coeff=NULL;
FilterCopy(filter, filterSrc);
return filter;
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
void FilterDealloc(FILTER *filter)
{
if (filter->coeff!=NULL){
free(filter->coeff);
}
free(filter);
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
void FilterInit(FILTER *filter, int size, int firstIndex, Real *coeff)
{
int i;
filter->size=size;
filter->firstIndex=firstIndex;
filter->center=-firstIndex;
filter->coeff = (Real *)calloc(size, sizeof(Real));
if (coeff != NULL){
for (i=0; i<size; i++){
filter->coeff[i] = coeff[i];
}
}
else{
for (i=0; i<size; i++){
filter->coeff[i]=0;
}
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
Real FilterCoeff(FILTER *filter, int index)
{
return filter->coeff[index-filter->firstIndex];
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
void FilterCopy(FILTER *filterDest, FILTER *filterSrc)
{
if (filterDest->coeff!=NULL){
free(filterDest->coeff);
}
FilterInit(filterDest, filterSrc->size, filterSrc->firstIndex, filterSrc->coeff);
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* FILTERSET */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
FILTERSET * FilterSetAllocDef(void)
{
FILTERSET *filterset;
if((filterset = (FILTERSET *)malloc(sizeof(FILTERSET)))==NULL){
return NULL;
}
filterset->symmetric=FALSE;
filterset->analysisLow=NULL;
filterset->analysisHigh=NULL;
filterset->synthesisLow=NULL;
filterset->synthesisHigh=NULL;
return filterset;
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
FILTERSET * FilterSetAlloc(int symmetric,
Real *anLow, int anLowSize, int anLowFirst,
Real *synLow, int synLowSize, int synLowFirst)
{
FILTERSET *filterset;
int i, sign;
if((filterset = (FILTERSET *)malloc(sizeof(FILTERSET)))==NULL){
return NULL;
}
/* 7/9/2002 */
filterset->symmetric = symmetric;
filterset->analysisLow = FilterAlloc(anLowSize, anLowFirst, anLow);
//- TO DO : Error checking
// If no synthesis coeffs are given, assume wavelet is orthogonal
if (synLow == NULL){
filterset->synthesisLow=FilterAllocCopy(filterset->analysisLow);
//- TO DO : Error checking
// 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 = FilterAlloc(filterset->analysisLow->size,
2 - filterset->analysisLow->size -
filterset->analysisLow->firstIndex, NULL);
//- TO DO : Error checking
// 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];
assert(1-i-filterset->analysisLow->firstIndex-filterset->analysisHigh->firstIndex >= 0);
assert (1-i-filterset->analysisLow->firstIndex - filterset->analysisHigh->firstIndex
< filterset->analysisHigh->size);
sign *= -1;
}
// Copy the high pass analysis filter to the synthesis filter
filterset->synthesisHigh = FilterAllocCopy(filterset->analysisHigh);
//- TO DO : Error checking
}
else{
// If separate synthesis coeffs given, assume biorthogonal
filterset->synthesisLow = FilterAlloc(synLowSize, synLowFirst, synLow);
//- TO DO : Error checking
// 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 = FilterAlloc(filterset->synthesisLow->size,
2 - filterset->synthesisLow->size - filterset->synthesisLow->firstIndex, NULL);
//- TO DO : Error checking
// 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];
assert (1 - i - filterset->synthesisLow->firstIndex -
filterset->analysisHigh->firstIndex >= 0);
assert (1 - i - filterset->synthesisLow->firstIndex -
filterset->analysisHigh->firstIndex < filterset->analysisHigh->size);
sign *= -1;
}
filterset->synthesisHigh = FilterAlloc(filterset->analysisLow->size,
2 - filterset->analysisLow->size - filterset->analysisLow->firstIndex, NULL);
//- TO DO : Error checking
// 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];
assert (1 - i - filterset->analysisLow->firstIndex -
filterset->synthesisHigh->firstIndex >= 0);
assert (1 - i - filterset->analysisLow->firstIndex -
filterset->synthesisHigh->firstIndex < filterset->synthesisHigh->size);
sign *= -1;
}
}
return filterset;
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
FILTERSET * FilterSetAllocCopy(FILTERSET *filtersetSrc)
{
FILTERSET *filterset;
if((filterset = (FILTERSET *)malloc(sizeof(FILTERSET)))==NULL){
return NULL;
}
FilterSetCopy(filterset, filtersetSrc);
return filterset;
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
void FilterSetDealloc(FILTERSET *filterset)
{
FilterDealloc(filterset->analysisLow);
FilterDealloc(filterset->analysisHigh);
FilterDealloc(filterset->synthesisLow);
FilterDealloc(filterset->synthesisHigh);
free(filterset);
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
void FilterSetCopy(FILTERSET *filtersetDest, FILTERSET *filtersetSrc)
{
filtersetDest->symmetric=filtersetSrc->symmetric;
filtersetDest->analysisLow = FilterAllocCopy(filtersetSrc->analysisLow);
filtersetDest->analysisHigh = FilterAllocCopy(filtersetSrc->analysisHigh);
filtersetDest->synthesisLow = FilterAllocCopy(filtersetSrc->synthesisLow);
filtersetDest->synthesisHigh = FilterAllocCopy(filtersetSrc->synthesisHigh);
}
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
void InitializeFilterSets(void)
{
Haar = FilterSetAlloc(FALSE, HaarCoeffs, 2, 0, NULL, 0, 0);
Daub4 = FilterSetAlloc(FALSE, Daub4Coeffs, 4, 0, NULL, 0, 0);
Daub6 = FilterSetAlloc(FALSE, Daub6Coeffs, 6, 0, NULL, 0, 0);
Daub8 = FilterSetAlloc(FALSE, Daub8Coeffs, 8, 0, NULL, 0, 0);
Antonini = FilterSetAlloc(TRUE, AntoniniAnalysis, 9, -4,
AntoniniSynthesis, 7, -3);
Villa1810 = FilterSetAlloc(TRUE, Villa1810Analysis, 10, -4,
Villa1810Synthesis, 18, -8);
Adelson = FilterSetAlloc(TRUE, AdelsonCoeffs, 9, -4, NULL, 0, 0);
Brislawn = FilterSetAlloc(TRUE, BrislawnAnalysis, 9, -4,
BrislawnSynthesis, 7, -3);
Brislawn2 = FilterSetAlloc(TRUE, Brislawn2Analysis, 10, -4,
Brislawn2Synthesis, 10, -4);
Villa1 = FilterSetAlloc(TRUE, Villa1Analysis, 9, -4, Villa1Synthesis, 7, -3);
Villa2 = FilterSetAlloc(TRUE, Villa2Analysis, 13, -6, Villa2Synthesis, 11, -5);
Villa3 = FilterSetAlloc(TRUE, Villa3Analysis, 6, -2, Villa3Synthesis, 10, -4);
Villa4 = FilterSetAlloc(TRUE, Villa4Analysis, 5, -2, Villa4Synthesis, 3, -1);
Villa5 = FilterSetAlloc(TRUE, Villa5Analysis, 2, 0, Villa5Synthesis, 6, -2);
Villa6 = FilterSetAlloc(TRUE, Villa6Analysis, 9, -4, Villa6Synthesis, 3, -1);
Odegard = FilterSetAlloc(TRUE, OdegardAnalysis, 9, -4, OdegardSynthesis, 7, -3);
}
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
void RemoveFilterSets(void)
{
FilterSetDealloc(Haar);
FilterSetDealloc(Daub4);
FilterSetDealloc(Daub6);
FilterSetDealloc(Daub8);
FilterSetDealloc(Antonini);
FilterSetDealloc(Villa1810);
FilterSetDealloc(Adelson);
FilterSetDealloc(Brislawn);
FilterSetDealloc(Brislawn2);
FilterSetDealloc(Villa1);
FilterSetDealloc(Villa2);
FilterSetDealloc(Villa3);
FilterSetDealloc(Villa4);
FilterSetDealloc(Villa5);
FilterSetDealloc(Villa6);
FilterSetDealloc(Odegard);
}
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
void FilterWarning(char *fmt, ...)
{
va_list argptr;
va_start( argptr, fmt );
fprintf( stderr, "FilterWarning: " );
vprintf( fmt, argptr );
va_end( argptr );
}
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
void FilterError(char *fmt, ...)
{
va_list argptr;
va_start( argptr, fmt );
fprintf(stderr, "FilterError: " );
vprintf( fmt, argptr );
va_end( argptr );
exit( -1 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -