00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <time.h>
00004 #include <string.h>
00005 #include <math.h>
00006 #include <mkl.h>
00007 #include <omp.h>
00008 #include <sys/param.h>
00009 #include "finterpolate.h"
00010
00011
00012 #define minval(x,y) (((x) < (y)) ? (x) : (y))
00013 #define maxval(x,y) (((x) < (y)) ? (y) : (x))
00014
00015 #define kInterpDataDir "proj/libs/interpolate/data"
00016
00017 #define fint_wiener 1
00018 #define fint_linear 2
00019 #define fint_cubic_conv 3
00020
00021 static double sinc(double x)
00022 {
00023 if (fabs(x) < (1.e-10))
00024 return 1.;
00025 else
00026 return sin(M_PI*x)/(M_PI*x);
00027 }
00028
00029 int init_finterpolate_wiener_old(
00030 struct fint_struct *pars,
00031 int order,
00032 int edgemode,
00033
00034 float extrapolate,
00035 int minorder,
00036 int nconst,
00037
00038 const char *path
00039 )
00040 {
00041 int status;
00042 int table=0;
00043 char filename[PATH_MAX];
00044
00045 snprintf(filename, sizeof(filename), "%s/%s/acor1d_80x100_double.txt", path, kInterpDataDir);
00046 status=init_finterpolate_wiener(pars,order,edgemode,extrapolate,minorder,nconst,table,&filename, path);
00047
00048 return status;
00049 }
00050
00051 int init_finterpolate_wiener(
00052 struct fint_struct *pars,
00053 int order,
00054 int edgemode,
00055
00056 float extrapolate,
00057 int minorder,
00058 int nconst,
00059
00060 int cortable,
00061
00062 char **filenamep,
00063
00064 const char *path
00065 )
00066 {
00067 const int malign=32;
00068 const int nsubin0=100;
00069 const int maxoff=40;
00070 int i,j,k;
00071 int ishift,offset,order2,nextra,nshifts,shift0;
00072 FILE *fileptr;
00073 double *acor,*a,*rh,*a1b,*a1r,*coeffd;
00074 double bta1b,bta1r,c;
00075 double *b,*rhc,*bta1b1,*help;
00076 double xc,xp,sum;
00077 int info;
00078 char uplo[] = "U";
00079 int ione = 1;
00080 double pmin,regul;
00081 int minorder1,curorder,imin,imax,icent,is0,i0,nrh;
00082
00083 pars->method=fint_wiener;
00084 pars->kersx=NULL;
00085
00086 if ((order%2) != 0) {
00087 printf("Order must be even!\n");
00088 return 2;
00089 }
00090 if ((minorder%2) != 0) {
00091 printf("Minorder must be even!\n");
00092 return 2;
00093 }
00094 if (nconst < 0) {
00095 printf("Number of constraints must be non-negative!\n");
00096 return 2;
00097 }
00098 order2=order/2;
00099 if (edgemode==0) {
00100 nshifts=nsubin0+1;
00101 shift0=0;
00102 if (extrapolate!=0) {
00103 printf("Warning: Can't extrapolate for edgemode==0.\n");
00104 extrapolate=0.0f;
00105 }
00106 }
00107 nextra=maxval(0,extrapolate)*nsubin0+2;
00108 shift0=(order2-1)*nsubin0+nextra;
00109 nshifts=(order-1)*nsubin0+2*nextra+1;
00110 icent=(nshifts-1)/2;
00111 pars->edgemode=edgemode;
00112 pars->extrapolate=extrapolate;
00113 pars->order=order;
00114 pars->nshifts=nshifts;
00115 pars->shift0=shift0;
00116 pars->fover=(float)nsubin0;
00117 pars->nsub=nsubin0+1;
00118 pars->kersx=(float *)(MKL_malloc(nshifts*order*sizeof(float),malign));
00119
00120 regul=1/400./400.;
00121 pmin=regul;
00122
00123 if ((cortable < 0) || (cortable > 1)) {
00124 printf("Illegal cortable passed to finterpolate!\n");
00125 return 1;
00126 }
00127 if (cortable == 0) {
00128 pars->filename=strdup(*filenamep);
00129 }
00130 if (cortable == 1) {
00131 char dfile[PATH_MAX];
00132 snprintf(dfile, sizeof(dfile), "%s/%s/acor1d_80x100_double.txt", path, kInterpDataDir);
00133 pars->filename=strdup(dfile);
00134 }
00135 fileptr = fopen (pars->filename, "r");
00136 if (fileptr == NULL) {
00137 printf("File not found in finterpolate!\n");
00138 return 2;
00139 }
00140 if (cortable != 0) {
00141 if (filenamep != NULL) {
00142 *filenamep=strdup(pars->filename);
00143 }
00144 }
00145 acor=(double *)(MKL_malloc((nsubin0*maxoff+1)*sizeof(double),malign));
00146 for (i=0;i<nsubin0*maxoff+1;i++) fscanf(fileptr,"%lf",acor+i);
00147 fclose(fileptr);
00148
00149 nrh=maxval(1,nconst);
00150 a=(double *)(MKL_malloc(order*order*sizeof(double),malign));
00151 rh=(double *)(MKL_malloc(nrh*order*sizeof(double),malign));
00152 a1r=(double *)(MKL_malloc(nrh*order*sizeof(double),malign));
00153 a1b=(double *)(MKL_malloc(nrh*order*sizeof(double),malign));
00154 coeffd=(double *)(MKL_malloc(order*sizeof(double),malign));
00155 b=(double *)(MKL_malloc(nrh*order*sizeof(double),malign));
00156 rhc=(double *)(MKL_malloc(nrh*sizeof(double),malign));
00157 help=(double *)(MKL_malloc(nrh*sizeof(double),malign));
00158 bta1b1=(double *)(MKL_malloc(nrh*nrh*sizeof(double),malign));
00159 minorder1=minorder;
00160 if (edgemode == 0) minorder1=order;
00161 for (curorder=minorder1;curorder<=order;curorder=curorder+2) {
00162 for (i=0;i<curorder;i++) {
00163 for (j=i;j<curorder;j++) {
00164 offset=nsubin0*(j-i);
00165 a[i*curorder+j]=acor[offset];
00166 a[j*curorder+i]=acor[offset];
00167 }
00168 a[i*curorder+i]=a[i*curorder+i]+regul;
00169 }
00170 dpotrf(uplo,&curorder,a,&curorder,&info);
00171
00172 imin=icent-(order-curorder+1)*nsubin0/2;
00173 imax=icent+(order-curorder+1)*nsubin0/2;
00174 if (curorder == minorder) {
00175 imin=0;
00176 imax=nshifts-1;
00177 }
00178 for (ishift=imin;ishift<=imax;ishift++) {
00179
00180
00181 is0=(ishift-shift0+nsubin0*2*order) % nsubin0;
00182
00183 is0=ishift-is0-nsubin0*(curorder/2-1);
00184
00185 is0=maxval(is0,icent-(order-1)*nsubin0/2);
00186 is0=minval(is0,icent+(order-1)*nsubin0/2-(curorder-1)*nsubin0);
00187 i0=(is0-icent+(order-1)*nsubin0/2)/nsubin0;
00188
00189 for (i=0;i<curorder;i++) {
00190 offset=ishift-(shift0+nsubin0*(i+i0-order/2+1));
00191 if (offset<0) offset=-offset;
00192 rh[i]=acor[offset]+pmin*sinc((offset+0.0)/nsubin0);
00193 }
00194
00195 switch (nconst) {
00196 case 0:
00197 for (i=0;i<curorder;i++) coeffd[i]=rh[i];
00198 dpotrs(uplo,&curorder,&ione,a,&curorder,coeffd,&curorder,&info);
00199 break;
00200 case 1:
00201 for (i=0;i<curorder;i++) a1b[i]=1.;
00202 dpotrs(uplo,&curorder,&ione,a,&curorder,a1b,&curorder,&info);
00203 bta1b=0.;
00204 for (i=0;i<curorder;i++) bta1b=bta1b+a1b[i];
00205 for (i=0;i<curorder;i++) a1r[i]=rh[i];
00206 dpotrs(uplo,&curorder,&ione,a,&curorder,a1r,&curorder,&info);
00207 bta1r=0.0;
00208 for (i=0;i<curorder;i++) bta1r=bta1r+a1r[i];
00209 c=(bta1r-1.)/bta1b;
00210 for (i=0;i<curorder;i++) coeffd[i]=a1r[i]-c*a1b[i];
00211 break;
00212 default:
00213 for (i=0;i<curorder;i++) {
00214 offset=ishift-(shift0+nsubin0*(i+i0-order/2+1));
00215 xc=(offset+0.0)/nsubin0;
00216 xp=1.0;
00217 for (j=0;j<nconst;j++) {
00218 b[j*curorder+i]=xp;
00219 xp=xp*xc;
00220 }
00221 }
00222 rhc[0]=1;
00223 for (j=1;j<nconst;j++) rhc[j]=0;
00224 for (i=0;i<curorder*nconst;i++) a1b[i]=b[i];
00225 dpotrs(uplo,&curorder,&nconst,a,&curorder,a1b,&curorder,&info);
00226 for (i=0;i<nconst;i++) {
00227 for (j=0;j<nconst;j++) {
00228 sum=0.0;
00229 for (k=0;k<curorder;k++)
00230 sum=sum+a1b[i*curorder+k]*b[j*curorder+k];
00231 bta1b1[i*nconst+j]=sum;
00232 }
00233 }
00234 dpotrf(uplo,&nconst,bta1b1,&nconst,&info);
00235 for (i=0;i<nconst;i++) {
00236 sum=0.0;
00237 for (k=0;k<curorder;k++) sum=sum+a1b[i*curorder+k]*rh[k];
00238 help[i]=sum-rhc[i];
00239 }
00240 dpotrs(uplo,&nconst,&ione,bta1b1,&nconst,help,&nconst,&info);
00241 for (i=0;i<curorder;i++) a1r[i]=rh[i];
00242 dpotrs(uplo,&curorder,&ione,a,&curorder,a1r,&curorder,&info);
00243 for (i=0;i<curorder;i++) {
00244 sum=0.0;
00245 for (k=0;k<nconst;k++) sum=sum+a1b[k*curorder+i]*help[k];
00246 coeffd[i]=a1r[i]-sum;
00247 }
00248 break;
00249 }
00250
00251
00252
00253 for (i=0;i<order;i++) pars->kersx[ishift*order+i]=0.0f;
00254 for (i=0;i<curorder;i++) pars->kersx[ishift*order+i+i0]=(float)coeffd[i];
00255
00256 }
00257 }
00258
00259
00260
00261
00262
00263 MKL_free(acor);
00264 MKL_free(a);
00265 MKL_free(a1r);
00266 MKL_free(a1b);
00267 MKL_free(rh);
00268 MKL_free(coeffd);
00269 MKL_free(b);
00270 MKL_free(rhc);
00271 MKL_free(help);
00272 MKL_free(bta1b1);
00273
00274 return 0;
00275 }
00276
00277 int init_finterpolate_linear(
00278 struct fint_struct *pars,
00279 float extrapolate
00280 )
00281 {
00282
00283 pars->method=fint_linear;
00284 pars->extrapolate=extrapolate;
00285
00286 return 0;
00287 }
00288
00289 int init_finterpolate_cubic_conv(
00290 struct fint_struct *pars,
00291 int edgemode,
00292
00293 float extrapolate
00294 )
00295 {
00296
00297 pars->method=fint_cubic_conv;
00298 pars->edgemode=edgemode;
00299 pars->extrapolate=extrapolate;
00300
00301 return 0;
00302 }
00303
00304 int free_finterpolate(
00305 struct fint_struct *pars
00306 )
00307 {
00308 if (pars->method==fint_wiener) {
00309
00310 if (pars->kersx!=NULL) {
00311 MKL_free (pars->kersx);
00312 free (pars->filename);
00313 }
00314 }
00315
00316 return 0;
00317 }
00318
00319 int winterpolate(
00320 struct fint_struct *pars,
00321 float *image_in,
00322 float *xin,
00323 float *yin,
00324 float *image_out,
00325 int nxin,
00326 int nyin,
00327 int nleadin,
00328 int nx,
00329 int ny,
00330 int nlead,
00331 float fillval
00332 )
00333
00334 {
00335 int i,j,i1,j1;
00336 int order2;
00337 float *xker;
00338 const int ione = 1;
00339 int malign=32;
00340 int ixin,iyin,ixin1,iyin1;
00341 float *ixins,*iyins,*ixin1s,*iyin1s;
00342 float fxin1,fyin1,fxin2,fyin2;
00343 float *fxins,*fyins,*xinp,*yinp,*fxin1s,*fyin1s;
00344 float *xk1,*xk2,*yk1,*yk2;
00345 float *imp;
00346 float sum,sum1;
00347 float *kersx;
00348 int ixmax,iymax;
00349 float xmax,ymax;
00350 int order,shift0,edgemode;
00351 float extrapolate;
00352 float x,y,help;
00353
00354 order=pars->order;
00355 kersx=pars->kersx;
00356 shift0=pars->shift0;
00357 edgemode=pars->edgemode;
00358 extrapolate=pars->extrapolate;
00359
00360 order2=order/2;
00361 ixmax=nxin-order2;
00362 iymax=nyin-order2;
00363 xmax=(float)ixmax;
00364 ymax=(float)iymax;
00365
00366 #pragma omp parallel default(none)\
00367 private(ixins,iyins,fxins,fyins,ixin1s,iyin1s,fxin1s,fyin1s,xker) \
00368 private (i,j,xinp,yinp,ixin,iyin,ixin1,iyin1,fxin1,fyin1,fxin2,fyin2,imp) \
00369 private (xk1,xk2,yk1,yk2,sum,sum1,i1,j1,x,y,help) \
00370 shared (pars,nlead,nx,ny,xin,yin,nleadin,nxin,nyin,image_in,image_out,order) \
00371 shared (malign,order2,kersx,ixmax,iymax,xmax,ymax,shift0,edgemode,extrapolate,fillval)
00372 {
00373 ixins=(float *)(MKL_malloc(nx*sizeof(float),malign));
00374 iyins=(float *)(MKL_malloc(nx*sizeof(float),malign));
00375 fxins=(float *)(MKL_malloc(nx*sizeof(float),malign));
00376 fyins=(float *)(MKL_malloc(nx*sizeof(float),malign));
00377 ixin1s=(float *)(MKL_malloc(nx*sizeof(float),malign));
00378 iyin1s=(float *)(MKL_malloc(nx*sizeof(float),malign));
00379 fxin1s=(float *)(MKL_malloc(nx*sizeof(float),malign));
00380 fyin1s=(float *)(MKL_malloc(nx*sizeof(float),malign));
00381
00382 xker=(float *)(MKL_malloc(order*sizeof(float),malign));
00383
00384
00385
00386 switch(order) {
00387 case 2:
00388 #define OOO1 2
00389 #define OOO2 1
00390 #include "finterpolate.include"
00391 #undef OOO1
00392 #undef OOO2
00393 break;
00394 case 4:
00395 #define OOO1 4
00396 #define OOO2 2
00397 #include "finterpolate.include"
00398 #undef OOO1
00399 #undef OOO2
00400 break;
00401 case 6:
00402 #define OOO1 6
00403 #define OOO2 3
00404 #include "finterpolate.include"
00405 #undef OOO1
00406 #undef OOO2
00407 break;
00408 case 8:
00409 #define OOO1 8
00410 #define OOO2 4
00411 #include "finterpolate.include"
00412 #undef OOO1
00413 #undef OOO2
00414 break;
00415 case 10:
00416 #define OOO1 10
00417 #define OOO2 5
00418 #include "finterpolate.include"
00419 #undef OOO1
00420 #undef OOO2
00421 break;
00422 case 12:
00423 #define OOO1 12
00424 #define OOO2 6
00425 #include "finterpolate.include"
00426 #undef OOO1
00427 #undef OOO2
00428 break;
00429 case 14:
00430 #define OOO1 14
00431 #define OOO2 7
00432 #include "finterpolate.include"
00433 #undef OOO1
00434 #undef OOO2
00435 break;
00436 case 16:
00437 #define OOO1 16
00438 #define OOO2 8
00439 #include "finterpolate.include"
00440 #undef OOO1
00441 #undef OOO2
00442 break;
00443 case 18:
00444 #define OOO1 18
00445 #define OOO2 9
00446 #include "finterpolate.include"
00447 #undef OOO1
00448 #undef OOO2
00449 break;
00450 case 20:
00451 #define OOO1 20
00452 #define OOO2 10
00453 #include "finterpolate.include"
00454 #undef OOO1
00455 #undef OOO2
00456 break;
00457 case 22:
00458 #define OOO1 22
00459 #define OOO2 11
00460 #include "finterpolate.include"
00461 #undef OOO1
00462 #undef OOO2
00463 break;
00464 case 24:
00465 #define OOO1 24
00466 #define OOO2 12
00467 #include "finterpolate.include"
00468 #undef OOO1
00469 #undef OOO2
00470 break;
00471 case 26:
00472 #define OOO1 26
00473 #define OOO2 13
00474 #include "finterpolate.include"
00475 #undef OOO1
00476 #undef OOO2
00477 break;
00478 case 28:
00479 #define OOO1 28
00480 #define OOO2 14
00481 #include "finterpolate.include"
00482 #undef OOO1
00483 #undef OOO2
00484 break;
00485 case 30:
00486 #define OOO1 30
00487 #define OOO2 15
00488 #include "finterpolate.include"
00489 #undef OOO1
00490 #undef OOO2
00491 break;
00492 case 32:
00493 #define OOO1 32
00494 #define OOO2 16
00495 #include "finterpolate.include"
00496 #undef OOO1
00497 #undef OOO2
00498 break;
00499
00500 default:
00501 #define OOO1 order
00502 #define OOO2 order2
00503 #include "finterpolate.include"
00504 #undef OOO1
00505 #undef OOO2
00506 break;
00507 }
00508
00509 MKL_free(xker);
00510 MKL_free(ixins);
00511 MKL_free(iyins);
00512 MKL_free(fxins);
00513 MKL_free(fyins);
00514 MKL_free(ixin1s);
00515 MKL_free(iyin1s);
00516 MKL_free(fxin1s);
00517 MKL_free(fyin1s);
00518 }
00519
00520 return 0;
00521 }
00522
00523 int linterpolate(
00524 float *image_in,
00525 float *xin,
00526 float *yin,
00527 float *image_out,
00528 int nxin,
00529 int nyin,
00530 int nleadin,
00531 int nx,
00532 int ny,
00533 int nlead,
00534 float extrapolate,
00535 float fillval
00536 )
00537
00538 {
00539 int i,j;
00540 int malign=32;
00541 int ixin,iyin;
00542 float *ixins,*iyins;
00543 float fxin1,fyin1,fxin2,fyin2;
00544 float *xinp,*yinp;
00545 float *imp;
00546 float xmin,xmax,ymin,ymax;
00547
00548 xmin=-extrapolate;
00549 xmax=nxin-1.0f+extrapolate;
00550 ymin=-extrapolate;
00551 ymax=nyin-1.0f+extrapolate;
00552
00553 #pragma omp parallel default(none) \
00554 private(ixins,iyins,i,j,xinp,yinp,ixin,iyin,fxin1,fyin1,fxin2,fyin2,imp) \
00555 shared(image_in,xin,yin,image_out,extrapolate,fillval) \
00556 shared(nx,ny,nlead,nxin,nyin,nleadin) \
00557 shared(malign,xmin,xmax,ymin,ymax)
00558 {
00559 ixins=(float *)(MKL_malloc(nx*sizeof(float),malign));
00560 iyins=(float *)(MKL_malloc(nx*sizeof(float),malign));
00561
00562 #pragma omp for
00563 for (j=0; j<ny; j++) {
00564 xinp=xin+j*nlead;
00565 vsFloor(nx,xinp,ixins);
00566 yinp=yin+j*nlead;
00567 vsFloor(nx,yinp,iyins);
00568 for (i=0; i<nx; i++) {
00569 ixin=(int)ixins[i];
00570 iyin=(int)iyins[i];
00571 if ((ixin>=0) && (ixin <(nxin-1)) && (iyin>=0) && (iyin <(nyin-1))) {
00572
00573
00574 fxin1=xinp[i]-ixin;
00575 fyin1=yinp[i]-iyin;
00576 fxin2=1.0f-fxin1;
00577 fyin2=1.0f-fyin1;
00578
00579 imp=image_in+ixin+nleadin*iyin;
00580
00581
00582 image_out[i+nlead*j]=fyin2*(fxin2*imp[0]+fxin1*imp[1])+
00583 fyin1*(fxin2*imp[nleadin]+fxin1*imp[nleadin+1]);
00584 }
00585 else {
00586 if ((xinp[i]>=xmin) && (xinp[i]<=xmax) && (yinp[i]>=ymin) && (yinp[i]<=ymax)) {
00587
00588
00589 ixin=maxval(0,minval(ixin,nxin-2));
00590 iyin=maxval(0,minval(iyin,nyin-2));
00591
00592 fxin1=xinp[i]-ixin;
00593 fyin1=yinp[i]-iyin;
00594 fxin2=1.0f-fxin1;
00595 fyin2=1.0f-fyin1;
00596
00597 imp=image_in+ixin+nleadin*iyin;
00598
00599
00600 image_out[i+nlead*j]=fyin2*(fxin2*imp[0]+fxin1*imp[1])+
00601 fyin1*(fxin2*imp[nleadin]+fxin1*imp[nleadin+1]);
00602 }
00603 else {
00604
00605 image_out[i+nlead*j]=fillval;
00606 }
00607 }
00608 }
00609 }
00610
00611 MKL_free(ixins);
00612 MKL_free(iyins);
00613 }
00614
00615 return 0;
00616 }
00617
00618 int ccinterpolate(
00619 float *image_in,
00620 float *xin,
00621 float *yin,
00622 float *image_out,
00623 int nxin,
00624 int nyin,
00625 int nleadin,
00626 int nx,
00627 int ny,
00628 int nlead,
00629 int edgemode,
00630 float extrapolate,
00631 float fillval
00632 )
00633
00634 {
00635 int i,j,i1;
00636 float xker[4],yker[4];
00637 int malign=32;
00638 int ixin,iyin;
00639 float *ixins,*iyins;
00640 float *xinp,*yinp;
00641 float *imp;
00642 float sum;
00643 float s,s2;
00644 float xmin,xmax,ymin,ymax;
00645
00646 if (edgemode == 0) {
00647 xmin=1.0f;
00648 xmax=nxin-2.0f;
00649 ymin=1.0f;
00650 ymax=nyin-2.0f;
00651 }
00652 else {
00653 xmin=-extrapolate;
00654 xmax=nxin-1.0f+extrapolate;
00655 ymin=-extrapolate;
00656 ymax=nyin-1.0f+extrapolate;
00657 }
00658
00659 #pragma omp parallel default(none) \
00660 private(ixins,iyins,i,j,xinp,yinp,ixin,iyin,imp,s,s2,xker,yker,sum,i1) \
00661 shared(image_in,xin,yin,image_out) \
00662 shared(nxin,nyin,nleadin,nx,ny,nlead,extrapolate,fillval) \
00663 shared(malign,xmin,xmax,ymin,ymax)
00664 {
00665 ixins=(float *)(MKL_malloc(nx*sizeof(float),malign));
00666 iyins=(float *)(MKL_malloc(nx*sizeof(float),malign));
00667
00668 #pragma omp for
00669 for (j=0; j<ny; j++) {
00670 xinp=xin+j*nlead;
00671 vsFloor(nx,xinp,ixins);
00672 yinp=yin+j*nlead;
00673 vsFloor(nx,yinp,iyins);
00674 for (i=0; i<nx; i++) {
00675 ixin=(int)ixins[i];
00676 iyin=(int)iyins[i];
00677 if ((ixin>=1) && (ixin <(nxin-2)) && (iyin>=1) && (iyin <(nyin-2))) {
00678
00679
00680
00681
00682 s=xinp[i]-ixin;
00683 s2 = s*s;
00684 xker[0] = -s*(1.0f - s*(2.0f - s));
00685 xker[1] = 2.0f - s2*(5.0f - 3.0f*s);
00686 xker[2] = s*(1.0f + s*(4.0f - 3.0f*s));
00687 xker[3] = -s2*(1.0f-s);
00688
00689 s=yinp[i]-iyin;
00690 s2 = s*s;
00691 yker[0] = -s*(1.0f - s*(2.0f - s));
00692 yker[1] = 2.0f - s2*(5.0f - 3.0f*s);
00693 yker[2] = s*(1.0f + s*(4.0f - 3.0f*s));
00694 yker[3] = -s2*(1.0f-s);
00695
00696 imp=image_in+ixin-1+nleadin*(iyin-1);
00697
00698
00699 sum=0.0f;
00700 for (i1=0; i1<4; i1++) {
00701 sum=sum+yker[i1]*(xker[0]*imp[0]+xker[1]*imp[1]+xker[2]*imp[2]+xker[3]*imp[3]);
00702 imp=imp+nleadin;
00703 }
00704 image_out[i+nlead*j]=sum/4;
00705 }
00706 else {
00707 if ((xinp[i]>=xmin) && (xinp[i]<=xmax) && (yinp[i]>=ymin) && (yinp[i]<=ymax)) {
00708
00709
00710 ixin=maxval(1,minval(ixin,nxin-3));
00711 iyin=maxval(1,minval(iyin,nyin-3));
00712
00713
00714
00715 s=xinp[i]-ixin;
00716 s2 = s*s;
00717 xker[0] = -s*(1.0f - s*(2.0f - s));
00718 xker[1] = 2.0f - s2*(5.0f - 3.0f*s);
00719 xker[2] = s*(1.0f + s*(4.0f - 3.0f*s));
00720 xker[3] = -s2*(1.0f-s);
00721
00722 s=yinp[i]-iyin;
00723 s2 = s*s;
00724 yker[0] = -s*(1.0f - s*(2.0f - s));
00725 yker[1] = 2.0f - s2*(5.0f - 3.0f*s);
00726 yker[2] = s*(1.0f + s*(4.0f - 3.0f*s));
00727 yker[3] = -s2*(1.0f-s);
00728
00729 imp=image_in+ixin-1+nleadin*(iyin-1);
00730
00731
00732 sum=0.0f;
00733 for (i1=0; i1<4; i1++) {
00734 sum=sum+yker[i1]*(xker[0]*imp[0]+xker[1]*imp[1]+xker[2]*imp[2]+xker[3]*imp[3]);
00735 imp=imp+nleadin;
00736 }
00737 image_out[i+nlead*j]=sum/4;
00738 }
00739 else {
00740
00741 image_out[i+nlead*j]=fillval;
00742 }
00743 }
00744 }
00745 }
00746
00747 MKL_free(ixins);
00748 MKL_free(iyins);
00749 }
00750
00751 return 0;
00752 }
00753
00754 int finterpolate(
00755 struct fint_struct *pars,
00756 float *image_in,
00757 float *xin,
00758 float *yin,
00759 float *image_out,
00760 int nxin,
00761 int nyin,
00762 int nleadin,
00763 int nx,
00764 int ny,
00765 int nlead,
00766 float fillval
00767 )
00768 {
00769 int status;
00770
00771 switch (pars->method) {
00772 case fint_wiener:
00773 status=winterpolate(pars,image_in,xin,yin,image_out,nxin,nyin,nleadin,nx,ny,nlead,fillval);
00774 break;
00775
00776 case fint_linear:
00777 status=linterpolate(image_in,xin,yin,image_out,nxin,nyin,nleadin,nx,ny,nlead,pars->extrapolate,fillval);
00778 break;
00779
00780 case fint_cubic_conv:
00781 status=ccinterpolate(image_in,xin,yin,image_out,nxin,nyin,nleadin,nx,ny,nlead,pars->edgemode,pars->extrapolate,fillval);
00782 break;
00783
00784 default:
00785 status=1;
00786 break;
00787 }
00788
00789 return status;
00790
00791 }
00792
00793 char *finterpolate_version()
00794 {
00795 return strdup("$Id: finterpolate.c,v 1.6 2011/12/06 18:11:03 arta Exp $");
00796 }
00797
00798