/* Evidence_combine.c ** This program is used to combine ** two evidence files and then output ** one combined evidence file and an image. ** based on Dempster-Shafer theory ** Note tha the uncertainty factors are assigned each source. ** COPYRIGHT: Brandt Tso */ #include #include #include #include #define class_max 21 void main(void) { FILE *fin[5], *fout[5]; unsigned int count[5], pix, cluster_num, num_pix; double max, certain[5], k; double uuc1[class_max], uuc2[class_max], combine[class_max], class_sum[100]; unsigned char in_file[50]; printf("\nThis program is used for the output of Maximum likelihood LOG domain file and output is still LOG domain file, for the use of other types of File as inputs one has to make a little modifications\n"); printf("Please make sure the class SEQUENCE from your input files are the SAME\n"); printf("Please make sure that the classes probabilities are sum to 1\n"); printf("***********************************************************************\n"); printf("Please input certainty factor for file 1:"); scanf("%lf", &certain[0]); printf("Please input certainty factor for file 2:"); scanf("%lf", &certain[1]); printf("Please input the total number of pixels"); scanf("%d",&num_pix); printf("Please input the total number of classes"); scanf("%d",&cluster_num); printf("Please input the file name for evidence 1 (i.e. U Matrix 1)"); scanf("%s",in_file); if((fin[1] = fopen(in_file,"r")) == NULL) { printf("Failed to open %s\n",in_file); exit(EXIT_FAILURE); } printf("Please input the file name for evidence 2 (i.e. U Matrix 2)"); scanf("%s",in_file); if((fin[2] = fopen(in_file,"r")) == NULL) { printf("Failed to open %s\n",in_file); exit(EXIT_FAILURE); } printf("Please input the file name for output evidence (i.e. New U Matrix)"); scanf("%s",in_file); if((fout[1] = fopen(in_file,"w")) == NULL)/*Output combined evidence (i.e. new U MATRIX)*/ { printf("Failed to open %s\n",in_file); exit(EXIT_FAILURE); } printf("Please input the file name for output image"); scanf("%s",in_file); if((fout[2] = fopen(in_file,"w")) == NULL)/*Output image*/ { printf("Failed to open %s\n",in_file); exit(EXIT_FAILURE); } printf("Start processing, please wait!!\n"); for(count[1] = 0; count[1] < num_pix;count[1]++) { class_sum[0] = 0; class_sum[1] = 0; for(count[2]=0;count[2] < cluster_num;count[2]++) { fscanf(fin[1],"%lf ",&uuc1[count[2]]); fscanf(fin[2],"%lf ",&uuc2[count[2]]); class_sum[0] = class_sum[0] + exp(uuc1[count[2]]); class_sum[1] = class_sum[1] + exp(uuc2[count[2]]); } if(class_sum[0]==0)class_sum[0]=1; if(class_sum[1]==0)class_sum[1]=1; for(count[2]=0;count[2] < cluster_num;count[2]++) { uuc1[count[2]]= (double) exp(uuc1[count[2]])/class_sum[0];/*Nomalisation*/ uuc2[count[2]]= (double) exp(uuc2[count[2]])/class_sum[1]; uuc1[count[2]]= uuc1[count[2]]*certain[0]; uuc2[count[2]]= uuc2[count[2]]*certain[1]; } k = 0; for(count[2]=0;count[2] < cluster_num;count[2]++) { for(count[3]=0;count[3] < cluster_num;count[3]++) { if(count[3] != count[2]) k = k+(uuc1[count[2]]*uuc2[count[3]]); } } if(k==1)k=0; pix = 1; for(count[2]=0;count[2] < cluster_num;count[2]++) { combine[count[2]] = (uuc1[count[2]]*uuc2[count[2]])+(uuc1[count[2]]*(1-certain[1]))+(uuc2[count[2]]*(1-certain[0])); combine[count[2]] = (double) combine[count[2]]/(1-k); fprintf(fout[1],"%lf ",log(combine[count[2]])); if(count[2]==0) max = combine[0]; if(combine[count[2]] > max) { max = combine[count[2]]; pix = count[2] + 1; } } fprintf(fout[2],"%c",pix); }/*End of num_of_pix*/ fclose(fin[1]); fclose(fin[2]); fclose(fout[1]); fclose(fout[2]); }