Advertisement
Kojima0502

combine

Oct 20th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.98 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 ix,iy;
  12.     float *file1,*file2;
  13.    
  14.    
  15.    
  16.    
  17.     if(argc!=10)
  18.     {
  19.         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",argv[0]);
  20.         exit(1);
  21.     }
  22.    
  23.     printf("OPEN R FILE NAME:%s\n",argv[1]);
  24.     printf("OPEN NIR FILE NAME:\%s\n",argv[2]);
  25.     printf("OPEN OUTPUT FILE NAME:%s\n",argv[3]);
  26.    
  27.     width1 = atoi(argv[4]); printf("W = %d,", width1);
  28.     height1 = atoi(argv[5]); printf("H = %d\n", height1);
  29.     width2 = atoi(argv[6]); printf("W = %d,", width2);
  30.     height2 = atoi(argv[7]); printf("H = %d\n", height2);
  31.     x = atoi(argv[8]); printf("X = %d\n" , x);
  32.     y = atoi(argv[9]); printf("Y = %d\n" , y);
  33.     ix=x/10;
  34.     iy=y/10;
  35.    
  36.     /*---------ÉÅÉÇÉäÇÃé©ìÆäÑìñ----------*/
  37.     file1= (float *)malloc(width1*height1*sizeof(float));
  38.     file2= (float *)malloc(width2*height2*sizeof(float));
  39.     //file3= (float *)malloc(width1*height1*sizeof(float));
  40.    
  41.     /*----------------ì¸óÕRâÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìäJén----------------------*/
  42.     if((fpi1=fopen(argv[1],"rb"))==NULL)
  43.     {       /*ÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉì*/
  44.         fprintf(stderr,"input file open error\n");
  45.         exit(1);
  46.     }
  47.    
  48.     fread((float *)file1,sizeof(float),width1*height1,fpi1);
  49.     /*----------------âÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìèIóπ----------------------*/
  50.     /*----------------ì¸óÕNIRâÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìäJén----------------------*/
  51.    
  52.     if((fpi2=fopen(argv[2],"rb"))==NULL)
  53.     {       /*ÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉì*/
  54.         fprintf(stderr,"output file open error\n");
  55.         exit(1);
  56.     }
  57.    
  58.     fread((float *)file2,sizeof(float),width2*height2,fpi2);
  59.     /*----------------âÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìèIóπ----------------------*/
  60.     /*----------------èoóÕRVIâÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìäJén----------------------*/
  61.     if((fpo=fopen(argv[3],"wb"))==NULL)
  62.     {       /*ÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉì*/
  63.         fprintf(stderr,"output file open error\n");
  64.         exit(1);
  65.     }
  66.      //fread((float *)file3,sizeof(float),width1*height1,fpo);
  67.      printf("check1\n"):
  68.     for(i=0;i<height1;i++)
  69. {
  70.     for(j=0;j<width1;j++)
  71.     {
  72.         if(i>iy && i<iy+height2 && j>ix && j<ix+width2)
  73.         {
  74.             dn1=file2[(i-iy)*width2+(j-ix)];
  75.         }
  76.         else
  77.         {
  78.             dn1=file1[i*width1+j];
  79.         }
  80.         //printf("check3\n");
  81.         fwrite(&dn1,sizeof(float),1,fpo);
  82.         printf("i=%d j=%d dn1=%f\n",i,j,dn1);
  83.        
  84.     }
  85. }
  86.   printf("check2\n"):
  87.    
  88.    
  89.     free(file1);
  90.     free(file2);
  91.     //free(file3);
  92.     fclose(fpi1);
  93.     fclose(fpi2);
  94.     fclose(fpo);
  95.    
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement