//***************************LN MODEL FOR SFS******************************** ** // Joao L. Fernandes, Jose R.A. Torreao // February 18, 2009 //****************************************************************************** //The input images should be in raw format, and, at most, 400x400 pixels in size //The window should be, at most, 19 pixels long //(this yields 9 discrete frequencies, by the FFTW routine employed). //****************************************************************************** #include #include #include #include #include #pragma hdrstop FILE *f1,*ref; char num; int Ni=256,Nj=256,NGREY=255; // Ni=number of lines; Nj=number of columns int W=3,i,j,ir,jr,i2,j2; // W = window size. double sigma=3, Sigma=2.25; // sigma=linear stage parameter (s.d. of gaussian weighting function). // Sigma=nonlinear stage parameter (s.d. of gaussian disparity-tuning functions). // sigma and Sigma in pixel units int k,Wj,pj,ppi,ppj,kinicial,kfinal,zinicial,zfinal; // Wj=number of horizontal frequency components unsigned char *image1r; fftw_complex *imag; fftw_plan plano; double pii = 3.141592654,xx[400],vzf[400][400][9],L[400][400][10]; double dx=2,jrl,irl,gaus,LM,LI,zfunc,*real,*zf; char automatic='y',ops; #pragma argsused int main(int argc, char* argv[]) { char arq1[40],arq3[40]; //Input of control parameters do { printf("=====Parameter Values=====\n"); printf("1. Number of lines of input image = %d\n",Ni); printf("2. Number of columns of input image = %d\n",Nj); printf("3. Window size (pixels)= %d\n",W); printf("4. Linear stage parameter: sigma (pixels) = %f\n",sigma); printf("5. Nonlinear stage parameter: Sigma (pixels) = %f\n",Sigma); printf("Any changes es or o ?"); scanf("%c",&ops); fflush(stdin); if(ops=='y') { printf("\nNumber:"); scanf("%d",&num); fflush(stdin); switch(num) { case 1: { printf("Number of lines of input image = "); scanf("%d",&Ni); fflush(stdin); break; } case 2: { printf("Number of columns of input image = "); scanf("%d",&Nj); fflush(stdin); break; } case 3 : { printf("W="); scanf("%d",&W); fflush(stdin); break; } case 4 : { printf("sigma="); scanf("%lf",&sigma); fflush(stdin); break; } case 5 : { printf("Sigma="); scanf("%lf",&Sigma); fflush(stdin); break; } } } } while(ops=='y'); // Input and output files: printf("enter the name of the input image:"); scanf("%s",arq1); printf("enter the name for the output depth matrix:"); scanf("%s",arq3); // Opening file for depth map f1=fopen(arq3,"w"); // Number of frequencies Wj=(int)(W/2)+1; //Parameter of the windows pj = (int)(W/2); /* --------------- Matrices ----------------------*/ image1r = (unsigned char *) malloc (Ni*Nj*sizeof(char)); real = (double *) malloc ((W*1+1)*sizeof(double)); zf = (double *) malloc (Ni*Nj*sizeof(double)); imag = (fftw_complex *) fftw_malloc((Wj)*sizeof(fftw_complex)); //Opening input image if ((ref = fopen(arq1,"rb")) == NULL) { printf("Can't open the image file %s\n",arq1); exit(1); } fread(image1r,Ni*Nj*sizeof(char),1,ref); fclose(ref); //Setting a 'metric' scale along the window for(j=0;j=Ni) { kinicial = Ni-1; } else { kinicial = i; } } if(j<0) { zinicial = 0; } else { if(j>=Nj) { zinicial = Nj-1; } else { zinicial = j; } } //Gaussian weighting function gaus= exp(-(((xx[jr])*(xx[jr])/(2*sigma*sigma)))); real[ir+jr] = (((double)image1r[kinicial*Nj+zinicial])*gaus)/((double)NGREY); jr++; } // j ir++; } // i fflush(stdout); fftw_execute(plano); fflush(stdout); for(j=0;j