// Prepare image (in-place) for cardinal spline interpolation. bool prepare_spline(float *img, int w, int h, int pd, int order) { if(order < 3) return true; // Replace nans and infinities with 0 for (int i = 0; i < w * h * pd; i++) if (!isfinite(img[i])) img[i] = 0; // Init poles of associated z-filter double z[5]; if (! fill_poles(z, order)) return false; int npoles = order / 2; for (int k = 0; k < pd; k++) { // Loop on image components for (int y = 0; y < h; y++) // Filter on lines invspline1D(img + (y*w+0)*pd + k, pd * 1, w, z, npoles); for (int x = 0; x < w; x++) // Filter on columns invspline1D(img + (0*w+x)*pd + k, pd * w, h, z, npoles); } return true; }
// Guoshen Yu, 2010.09.21, Windows version void finvspline(vector<float> &in,int order,vector<float>& out, int width, int height) // void finvspline(float *in,int order,float *out, int width, int height) { double *c,*d,z[5]; int npoles,nx,ny,x,y; ny = height; nx = width; /* initialize poles of associated z-filter */ switch (order) { case 2: z[0]=-0.17157288; /* sqrt(8)-3 */ break; case 3: z[0]=-0.26794919; /* sqrt(3)-2 */ break; case 4: z[0]=-0.361341; z[1]=-0.0137254; break; case 5: z[0]=-0.430575; z[1]=-0.0430963; break; case 6: z[0]=-0.488295; z[1]=-0.0816793; z[2]=-0.00141415; break; case 7: z[0]=-0.53528; z[1]=-0.122555; z[2]=-0.00914869; break; case 8: z[0]=-0.574687; z[1]=-0.163035; z[2]=-0.0236323; z[3]=-0.000153821; break; case 9: z[0]=-0.607997; z[1]=-0.201751; z[2]=-0.0432226; z[3]=-0.00212131; break; case 10: z[0]=-0.636551; z[1]=-0.238183; z[2]=-0.065727; z[3]=-0.00752819; z[4]=-0.0000169828; break; case 11: z[0]=-0.661266; z[1]=-0.27218; z[2]=-0.0897596; z[3]=-0.0166696; z[4]=-0.000510558; break; default: printf("finvspline: order should be in 2..11.\n"); exit(-1); } npoles = order/2; /* initialize double array containing image */ c = (double *)malloc(nx*ny*sizeof(double)); d = (double *)malloc(nx*ny*sizeof(double)); for (x=nx*ny;x--;) c[x] = (double)in[x]; /* apply filter on lines */ for (y=0;y<ny;y++) invspline1D(c+y*nx,nx,z,npoles); /* transpose */ for (x=0;x<nx;x++) for (y=0;y<ny;y++) d[x*ny+y] = c[y*nx+x]; /* apply filter on columns */ for (x=0;x<nx;x++) invspline1D(d+x*ny,ny,z,npoles); /* transpose directy into image */ for (x=0;x<nx;x++) for (y=0;y<ny;y++) out[y*nx+x] = (float)(d[x*ny+y]); /* free array */ free(d); free(c); }