双线性插值的代码优化

时间:2019-02-05 10:27:38

标签: c++ image-processing optimization interpolation bilinear-interpolation

我已经根据MATLAB示例实现了双线性插值算法: https://se.mathworks.com/matlabcentral/fileexchange/10772-fast-2-dimensional-interpolation; https://en.wikipedia.org/wiki/Bilinear_interpolation-单位平方公式。

对于加快实施速度将非常有用。有人可以给我建议如何优化代码以加快速度吗?请找到方法的一部分:

x_loops = floor((X_end-X_11)/pixel_size_mm)+1;
y_loops = floor((Y_end-Y_11)/pixel_size_mm)+1;


float** Zi = new float*[x_loops] ();
  for(int i = 0; i < x_loops; ++i) 
      Zi[i] = new float[y_loops] ();


n_dx = 1/(X_12 - X_11);
n_dy = 1/(Y_21 - Y_11);

Yi = Y_11;

int count = 0;
for(int i = 0; i < y_loops; i++)
   {
       Xi = X_11;          
       xi = 0;
       yi = 0;

   for(int j = 0; j < x_loops; j++)
      {

        xi = (Xi - X_11)*n_dx;
        yi = (Yi - Y_11)*n_dy;

        Xi += pixel_size_mm;

        fxi = floor(xi);
        fyi = floor(yi);

        dfxi = xi - fxi;
        dfyi = yi - fyi;

     Zi[j][i] = (Strain_image[fxi][fyi]*(1 - dfxi)*(1-dfyi) +  
       Strain_image[fxi+1][fyi]*dfxi*(1-dfyi) + Strain_image[fxi][fyi+1]* 
       (1-dfxi)*dfyi + Strain_image[fxi+1][fyi+1]*dfxi*dfyi);

      }

      Yi += pixel_size_mm;  

 }

  iMage(Zi, x_loops, y_loops,fX1,fY1);

  for(int i = 0; i < x_loops; ++i)
    delete [] Zi[i];
      delete[] Zi;

  for(int i = 0; i < number_of_RF_rows; ++i)
    delete [] Strain_image[i];
      delete[] Strain_image;

0 个答案:

没有答案