0

I have implemented bilinear interpolation algorithm according to the MATLAB example: https://se.mathworks.com/matlabcentral/fileexchange/10772-fast-2-dimensional-interpolation; https://en.wikipedia.org/wiki/Bilinear_interpolation - Unit square formula.

Would be great to speed up the implementation. Can somebody give me suggestions how to optimize the code for speeding it up? Please, find part of the method:

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;
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
AndriusS
  • 35
  • 1
  • 2
    Next, please read [ask] and [mcve], and [edit] your question accordingly. You have not posted a self-contained piece of code, it cannot be compiled as-is. You should always post complete pieces of code, it makes it easier for people to help you (and the easier this is, the more likely someone will take the time). – Cris Luengo Feb 05 '19 at 15:31
  • The code is confusing. In the main double loop none of the calculations depend on `i` and `j`. Is that how it is supposed to be? – freakish Feb 05 '19 at 15:33
  • One idea might be **OpenMP** which would mean adding the necessary compilation flags and libraries then prefixing your outer `for` loop with `#pragma omp parallel for`. I presume you are already compiling with optimisation on and also to allow `SIMD`. – Mark Setchell Feb 05 '19 at 15:58

0 Answers0