Advertisement
Kojima0502

combineD3

Dec 20th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc,char *argv[])
  6. {
  7.     FILE *fpi1,*fpi2,*fpo;
  8.     int i,j,height1,width1,height2,width2;
  9.     float dn1;
  10.     int x,y;
  11.     int re;
  12.     int ix,iy;
  13.     int iw,ih,iW,iH;
  14.     float *file1,*file2;//,*file3;
  15.    
  16.     if(argc!=11)
  17.     {
  18.         fprintf(stderr,"Usage: %s\n(2)Input_file1_filename\n(3)Input_file2_filename\n(4)Output_new_filename\n(5)width1\n(6)height1\n(7)width2\n(8)height2\n(9)x\n(10)y\n(11)re\n",argv[0]);
  19.         exit(1);
  20.     }
  21.    
  22.     printf("OPEN R FILE NAME:%s\n",argv[1]);
  23.     printf("OPEN NIR FILE NAME:\%s\n",argv[2]);
  24.     printf("OPEN OUTPUT FILE NAME:%s\n",argv[3]);
  25.    
  26.     width1 = atoi(argv[4]); printf("W = %d,", width1); //large
  27.     iw=width1/10;
  28.    
  29.     height1 = atoi(argv[5]); printf("H = %d\n", height1);//large
  30.     ih=height1/10;
  31.    
  32.     width2 = atoi(argv[6]); printf("W = %d,", width2); //small
  33.     iW=width2/10;
  34.    
  35.     height2 = atoi(argv[7]); printf("H = %d\n", height2); //small
  36.     iH=height2/10;
  37.    
  38.     x = atoi(argv[8]); printf("X = %d\n" , x); //upper Left
  39.     y = atoi(argv[9]); printf("Y = %d\n" , y); //upper Left
  40.    
  41.     re = atoi(argv[10]); printf("RE = %d\n" , re);
  42.     ix=x*re/10; //image coordinate of upper left : X
  43.     iy=y*re/10; //image coordinate of upper left : Y
  44.    
  45.     printf("check00\n");
  46.    
  47.     file1= (float *)malloc(iw*ih*sizeof(float)); //large
  48.     file2= (float *)malloc(iW*iH*sizeof(float)); //small
  49.     //file3= (float *)malloc(width1*height1*sizeof(float));
  50.    
  51.     //   printf("check0\n");
  52.    
  53.     //large
  54.     if((fpi1=fopen(argv[1],"rb+"))==NULL)
  55.     {
  56.         fprintf(stderr,"input file open error\n");
  57.         exit(1);
  58.     }
  59.     printf("check0-1\n");
  60.     fread((float *)file1,sizeof(float),iw*ih,fpi1);//large
  61.     printf("check0-2\n");
  62.    
  63.     //small
  64.     if((fpi2=fopen(argv[2],"rb"))==NULL)
  65.     {
  66.         fprintf(stderr,"input file open error\n");
  67.         exit(1);
  68.     }
  69.     printf("check0-3\n");
  70.     fread((float *)file2,sizeof(float),iW*iH,fpi2);//small
  71.     printf("check0-4\n");
  72.     /*
  73.      if((fpo=fopen(argv[3],"wb"))==NULL)
  74.      {
  75.      fprintf(stderr,"output file open error\n");
  76.      exit(1);
  77.      }
  78.      */
  79.     //fread((float *)file3,sizeof(float),width1*height1,fpo);
  80.     printf("check1\n");
  81.    
  82.     for(i=0;i<ih;i++)
  83.     {
  84.         for(j=0;j<iw;j++)
  85.         {
  86.             if(i>iy && i<iy+iH && j>ix && j<ix+iW)
  87.             {
  88.                 file1[i*iw+j]=file2[(i-iy)*iW+(j-ix)];
  89.             }
  90.             //else
  91.             // {
  92.             // dn1=file1[i*iw+j];
  93.             //}
  94.             //printf("check3\n");
  95.             //fwrite(&dn1,sizeof(float),1,fpo);
  96.             //printf("i=%d j=%d dn1=%f\n",i,j,dn1);
  97.         }
  98.     }
  99.    
  100.    
  101.    
  102.     printf("check2\n");
  103.    
  104.     free(file1);
  105.     free(file2);
  106.     //free(file3);
  107.     fclose(fpi1);
  108.     fclose(fpi2);
  109.     fclose(fpo);
  110.    
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement