Advertisement
d10070dd

rvi

Sep 14th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.40 KB | None | 0 0
  1. /*rvi program
  2. made by Yoshiyuki Yamamoto
  3. ver1.0 2004/5/30*/
  4.  
  5.  
  6. #include <stdio.h> /*このプログラムにstandart input/output headerを含む*/
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <time.h>
  10.  
  11. int main(int argc,char *argv[])
  12. {
  13.     FILE *fpi1,*fpi2,*fpo;                           /*入力ファイルポインタ*/
  14.     int i,j,height,width,header;     /*int型の最大値,最小値の変数の宣言*/
  15.     unsigned char dn1,dn2;
  16.     float dn3;                   /*RVIの変数の宣言*/
  17.     unsigned char *file1,*file2;
  18.     float *file3;                /*file1と呼ばれるfloat型のポインタ*/
  19.     float start,end;
  20.    
  21.     start=clock();
  22.  
  23.     /*--------引数の確認----------*/
  24.     if(argc!=7){
  25.         fprintf(stderr,"Usage: %s\n(2)Input_R_READ_filename\n(3)Input_NIR_READ_filename\n(4)Output_RVI_filename\n(5)width\n(6)height\n(7)header_size\n",argv[0]);
  26.         exit(1);
  27.                }
  28.     /*------------入力ファイルデータの表示----------------*/
  29.     printf("OPEN R FILE NAME:%s\n",argv[1]);
  30.     printf("OPEN NIR FILE NAME:\%s\n",argv[2]);
  31.     printf("OPEN OUTPUT FILE NAME:%s\n",argv[3]);
  32.     /*-----------引数の変数への渡し----------------------*/
  33.     width = atoi(argv[4]); printf("W = %d,", width);     /*入力する画像ファイルの横画素数*/
  34.     height = atoi(argv[5]); printf("H = %d\n", height);  /*入力する画像ファイルの縦画素数*/
  35.     header=atoi(argv[6]);printf("header=%d\n",header);   /*入力する画像ファイルのヘッダー数*/
  36.     /*---------メモリの自動割当----------*/
  37.     file1= (unsigned char *)malloc(width*height*sizeof(char));
  38.     file2= (unsigned char *)malloc(width*height*sizeof(char));
  39.     file3= (float *)malloc(width*height*sizeof(float));
  40.     /*----------------入力R画像ファイルのオープン開始----------------------*/
  41.     if((fpi1=fopen(argv[1],"rb"))==NULL){       /*ファイルのオープン*/
  42.     fprintf(stderr,"input file open error\n");
  43.     exit(1);
  44.     }
  45.     fread((unsigned char *)file1,sizeof(char),width*height,fpi1);
  46.     /*----------------画像ファイルのオープン終了----------------------*/
  47.     /*----------------入力NIR画像ファイルのオープン開始----------------------*/
  48.     if((fpi2=fopen(argv[2],"rb"))==NULL){       /*ファイルのオープン*/
  49.     fprintf(stderr,"output file open error\n");
  50.     exit(1);
  51.     }
  52.     fread((unsigned char *)file2,sizeof(char),width*height,fpi2);
  53.     /*----------------画像ファイルのオープン終了----------------------*/
  54.     /*----------------出力RVI画像ファイルのオープン開始----------------------*/
  55.     if((fpo=fopen(argv[3],"wb"))==NULL){       /*ファイルのオープン*/
  56.     fprintf(stderr,"output file open error\n");
  57.     exit(1);
  58.     }
  59.     fread((float *)file3,sizeof(float),width*height,fpo);
  60.     /*----------------画像ファイルのオープン終了----------------------*/
  61.  
  62.     /*-------RVIを求めるプログラム--------------------*/
  63.   for(i=header;i<height;i++){
  64.      for(j=header;j<width;j++){
  65.         dn1=file1[i*width+j];
  66.         dn2=file2[i*width+j];
  67.         dn3=(float)dn2/(float)dn1;
  68.         fwrite(&dn3,sizeof(float),1,fpo); /*m単位標高データの書き込み*/
  69.  
  70.      }
  71.   }
  72.   free(file1);
  73.   free(file2);
  74.   free(file3);
  75.   fclose(fpi1);
  76.   fclose(fpi2);
  77.   fclose(fpo);
  78.   end=clock();
  79.   printf("開始時間は,%f秒\n",start/1000);
  80.   printf("終了時間は,%f秒\n",end/1000);
  81.   printf("経過時間は,%f秒\n",(end-start)/1000);
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement