WEB开发网
开发学院软件开发VC DCT快速变换 阅读

DCT快速变换

 2010-07-25 20:45:40 来源:WEB开发网   
核心提示:后向回根void idct_backward(double *F, int deg){int i_deg,i_halfwing,total,wing,wings,winglen,halfwing;double temp1, temp2;total = 1 << deg;for(i_deg = deg-1;

后向回根

void idct_backward(double *F, int deg)
{
   int i_deg,i_halfwing,total,wing,wings,winglen,halfwing;
   double temp1, temp2;
   total = 1 << deg;
   for(i_deg = deg-1; i_deg >= 0; i_deg--)
   {
       wings = 1 << i_deg;
       winglen = total >> i_deg;
       halfwing = winglen >> 1;
       for(wing = 0; wing < wings; wing++)
       {
          for(i_halfwing = 0; i_halfwing < halfwing; i_halfwing++)
          {
              temp1 = F[wing*winglen+i_halfwing];
              temp2 = F[(wing+1)*winglen-1-i_halfwing]*C[winglen-1-i_halfwing];
              if(wing % 2)
              {
                 F[wing*winglen+i_halfwing] = (temp1-temp2)*0.5;
                 F[(wing+1)*winglen-1-i_halfwing] = (temp1+temp2)*0.5;
              }
              else
              {
                 F[wing*winglen+i_halfwing] = (temp1+temp2)*0.5;
                 F[(wing+1)*winglen-1-i_halfwing] = (temp1-temp2)*0.5;
              }
          }
       }
   }
}

完整实现一维IDCT变换:

void fidct_1D_no_param(double *F, int deg)
{
   initIDCTParam(deg);
   F[0] = F[0]*sqrt(2.0);
   fbitrev(F, deg);
   idct_forward(F, deg);
   idct_backward(F, deg);
}
void fdct_1D(double *f, int deg)
{
   fdct_1D_no_param(f, deg);
   int total = 1 << deg;
   double param = sqrt(2.0/total);
   for(int i = 0; i < total; i++)
       f[i] = param*f[i];
}

利用一维IDCT变换来实现二维IDCT变换:

void fidct_2D(double *F, int deg_row, int deg_col)
{
   int rows,cols,i_row,i_col;
   double   sqrtcolrow_div_two;
   rows = 1 << deg_row;
   cols = 1 << deg_col;
   init2D_Param(rows,cols);
   sqrtcolrow_div_two = (sqrt(double(rows*cols)))/2.0;
   for(i_row = 0; i_row < rows; i_row++)
   {
       fidct_1D_no_param(F+i_row*cols,deg_col);
   }
   for(i_col = 0; i_col < cols; i_col++)
   {
       for(i_row = 0; i_row < rows; i_row++)
       {
          temp_2D[i_row] = F[i_row*cols+i_col];
       }
       fidct_1D_no_param(temp_2D, deg_row);
       for(i_row = 0; i_row < rows; i_row++)
       {
          F[i_row*cols+i_col] = temp_2D[i_row]*sqrtcolrow_div_two;
       }
   }
   bHasInit=false;
}

上一页  1 2 3 4 5 6 7  下一页

Tags:DCT 快速 变换

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接