/* Pat_generator.c ** this program is used to ** generate AI (SNNS) training ** and test pattern ** The input pattern is statistic data type */ #include #include //#include #include #define band_max 20 void main(void) { FILE *fin[band_max+1], *fout; int judge1, num_of_band, num_of_class, total_pix; int i,count[5], num_pix, pix, img_row, img_col; float cue[band_max+1]; unsigned char store[2], in_file[50]; printf("Please specify the resulted file is used for training neural network (0) or for classifying (1):"); scanf("%d",&judge1); printf("Please input the total number for image bands(maximum %d):",band_max-2); scanf("%d",&num_of_band); if(judge1 == 0) { for(count[1]=1; count[1]<=num_of_band; count[1]++) { printf("Please input the training file name for band %d:", count[1]); scanf("%s",in_file); if((fin[count[1]] = fopen(in_file,"rb")) == NULL) { printf("Failed to open %s\n",in_file); exit(EXIT_FAILURE); } } printf("Please input the number of classes:"); scanf("%d",&num_of_class); printf("Please input the file name recording the training pixel number for each class:"); scanf("%s",in_file); if((fin[0] = fopen(in_file,"rb")) == NULL) { fprintf(stderr,"Failed to open %s\n",in_file); exit(EXIT_FAILURE); } total_pix = 0; for(count[1] = 1; count[1]<=num_of_class; count[1]++) { fscanf(fin[0],"%d",&num_pix); total_pix = total_pix+num_pix; } fseek(fin[0],0,0); } else { for(count[1]=1; count[1]<=num_of_band; count[1]++) { printf("Please input band %d image name:", count[1]); scanf("%s",in_file); if((fin[count[1]] = fopen(in_file,"rb")) == NULL) { printf("Failed to open %s\n",in_file); exit(EXIT_FAILURE); } } printf("Input image rows:"); scanf("%d",&img_row); printf("Input image columns:"); scanf("%d",&img_col); total_pix = img_row*img_col; } printf("Output file name:"); scanf("%s",in_file); if((fout = fopen(in_file,"w")) == NULL) { fprintf(stderr,"Failed to open %s\n",in_file); exit(EXIT_FAILURE); } fprintf(fout,"SNNS pattern definition file V3.2\n"); fprintf(fout,"generated at Thu May 21 00:00:00 2000\n"); fprintf(fout,"\n"); fprintf(fout,"\n"); fprintf(fout,"No. of patterns : %d\n", total_pix); fprintf(fout,"No. of input units : %d\n", num_of_band); if(judge1 == 0) fprintf(fout,"No. of output units : %d\n",num_of_class); fprintf(fout,"\n"); if(judge1 == 0) { i = 1; for(count[1] = 1; count[1]<=num_of_class; count[1]++) { fscanf(fin[0],"%d",&num_pix); for(count[2] = 0; count[2] < num_pix;count[2]++) { for(count[3] = 1; count[3]<=num_of_band; count[3]++) { fread(store,1,1,fin[count[3]]); pix = store[0]; cue[count[3]] = (float) pix/(float)255.0; } fprintf(fout,"# Input pattern %d:\n",i); for(count[3] = 1; count[3]<=num_of_band; count[3]++) fprintf(fout,"%.3f ",cue[count[3]]); fprintf(fout,"\n"); fprintf(fout,"# output pattern %d:\n",i); i++; for(count[3] = 1; count[3]