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;