/*---------------------------------------------------------------------------*/ /* */ /* Program: warp.c */ /* */ /* Purpose: This program takes in a collection of 2D landmark locations */ /* in one image and their corresponding locations in a second */ /* image and defines a global warping function from the first */ /* image to the second. This function is used to "morph" the */ /* first image into a new image. */ /* */ /* Author: John Gauch (based on code by Larry Lifshitz) */ /* */ /* Date: May 31, 1995 */ /* */ /* Note: Copyright (C) The University of Kansas, 1994, 1995 */ /*---------------------------------------------------------------------------*/ #include #include "invert.c" /*---------------------------------------------------------------------------*/ /* */ /* Purpose: This function returns value of basis function. */ /* */ /*---------------------------------------------------------------------------*/ float H(x1,y1,x2,y2) float x1,y1,x2,y2; { float dx, dy, dist; dx = x1-x2; dy = y1-y2; dist = dx*dx + dy*dy; if (dist>0.0001) return( dist*(float)log((double)dist)/(M_PI*8) ); else return(0); } /*---------------------------------------------------------------------------*/ /* */ /* Purpose: This is the main program. */ /* */ /*---------------------------------------------------------------------------*/ main(argc, argv) int argc; char *argv[]; { /* Image variables */ char Name1[50]; char Name2[50]; char Name3[50]; IM_TYPE *Image1; IM_TYPE *Image2; FLOAT_TYPE **Data1; FLOAT_TYPE **Data2; int PixType, Xdim,Ydim,Zdim, DimCnt; /* Program variables */ FILE *fd; int Debug = FALSE; int PtCnt; int i=0,j,x,y; float *x1, *y1; float *x2, *y2; float **Lmatrix; float **Linverse; float *Avector; float *Bvector; float Beta = 1000.0; float value, Xnew,Ynew; float v1,v2,v3,v4, w1,w2,w3,w4; /* Interpret program options */ printf("WARP Program - KUIM Version 1.0\n\n"); while ((++i=0 && Ynew>=0 && Xnew<(Xdim-1) && Ynew<(Ydim-1)) { v1 = v2 = v3 = v4 = Data1[(int)Ynew][(int)Xnew]; if (Xnew+1 < Xdim) v2 = Data1[(int)Ynew][(int)Xnew+1]; if (Ynew+1 < Ydim) v3 = Data1[(int)Ynew+1][(int)Xnew]; if ((Xnew+1 < Xdim) && (Ynew+1 < Ydim)) v4 = Data1[(int)Ynew+1][(int)Xnew+1]; w4 = (Xnew-(int)Xnew)*(Ynew-(int)Ynew); w3 = (1-Xnew+(int)Xnew)*(Ynew-(int)Ynew); w2 = (Xnew-(int)Xnew)*(1-Ynew+(int)Ynew); w1 = (1-Xnew+(int)Xnew)*(1-Ynew+(int)Ynew); Data2[y][x] = w1*v1 + w2*v2 + w3*v3 + w4*v4; } else Data2[y][x] = 0; } /* Write information to output image */ im_write(Image2, FLOAT, &(Data2[0][0])); im_free2D(Data1); im_free2D(Data2); exit(0); }