📄 newscramdegree.c~
字号:
/*********************************************************
* *
* Evenness *
* *
*********************************************************/
#include <tina/all_tina.h>
#include "bmp.h"#include "gnuplot_i.h"
//#include "func.h"
/*_____ EXTERN _____*/
extern double getZhiLuanDu_1(int **r, int **c, Imrect *srcIm, Imrect *destIm, int height, int width);
extern double getDSF(int **r, int **c, int height, int width);
extern double getGSF(Imrect *srcIm, Imrect *destIm, int height, int width);
extern double getDDR(Imrect *srcIm, Imrect *destIm, int height, int width);
/*-----------------------------------------------------------*/
static int iminarg1,iminarg2;
#define IMAX(a,b) (iminarg1 = (a),iminarg2 = (b),(iminarg1) > (iminarg2) ? (iminarg1) : (iminarg2))
static int scram_method = 0;
static int n_scram = 10;
static int MASK_width = 15;#define MAXPATHLEN 64static char directory_name[MAXPATHLEN];static char file_name[MAXPATHLEN];static char pathname[MAXPATHLEN];
static void *pdir=0, *pfile=0;
static void scram_choice_proc(int val)
{
scram_method = val;
}
static Imrect *read_image(void){ Imrect *srcIm;/*----------------Read the image---------------------------*/ (void) strip_spaces(file_name); (void) strip_spaces(directory_name); (void) string_append(pathname, directory_name, "/", file_name, NULL); srcIm = BmpToImrect(pathname);/*------------------------------------------------*/ return(srcIm);}
static void scram_proc(void)
{
Imrect *srcIm, *destIm;
int width, height;
int type;
BYTE pix;
int lx, ux, ly, uy;
Imregion *roi;/*
if (stack_check_types(IMRECT, NULL) == false)
{
error("Warning : wrong types on stack", warning);
return;
}
srcIm = (Imrect *) stack_pop(&type);*/ srcIm = read_image();
width = srcIm->width;
height = srcIm->height;
roi = srcIm->region;
if (roi == NULL) return;
lx = roi->lx;
ux = roi->ux;
ly = roi->ly;
uy = roi->uy;
destIm = im_alloc( height, width, roi, int_v );
int i, j;
int **trans_r, **trans_c, **tmp_r, **tmp_c, **dest_r, **dest_c;
trans_r = int_matrix(height, width);
trans_c = int_matrix(height, width);
tmp_r = int_matrix(height, width);
tmp_c = int_matrix(height, width);
dest_r = int_matrix(height, width);
dest_c = int_matrix(height, width);
for(i = 0; i < height; i++) //目标图象矩阵初始化
{
for(j = 0; j < width; j++)
{
dest_r[i][j] = i;
dest_c[i][j] = j;
}
}//+ char filename[128],filename1[128],filename2[128],filename3[128],filename4[128]; char fnpng[64]; char fnds[64],fndstxt[64],fndspng[64]; char string[25]; strcpy(filename,"plot/"); gcvt(MASK_width,5,string);// //strcat(filename,string); //strcat(filename,"/"); strcat(filename,string); strcat(filename, "_"); gcvt(height,5,string);// strcat(filename, string); strcat(filename, "x"); gcvt(width,5,string); strcat(filename, string); strcat(filename, "_"); //gcvt(n_scram,5,string);// //strcat(filename, string); //strcat(filename, "_");
//+
FILE * fp1, * fp2, * fp3, *fp4 ,*fp;
switch( scram_method )
{
case 0:
fibonacci_matrix(trans_r, trans_c, height, width); strcat(filename, "fibonacci_");
break;
case 1: if(width!=height) { printf("height%d!=width%d",height,width); return; }
arnold_matrix(trans_r, trans_c, height, width); strcat(filename, "arnold_");
break;
case 2:
qatlig_matrix(trans_r, trans_c, height, width); strcat(filename, "qatlig_");
break;
case 3:
hilbert_matrix(trans_r, trans_c, height, width); strcat(filename, "hilbert_");
break;
case 4: zigzag_matrix(trans_r, trans_c, height, width); strcat(filename, "zigzag_");
break;
case 5:
//latin_matrix(trans_r, trans_c, height, width); //strcat(filename, "latin_"); convey_matrix(trans_r, trans_c, height, width); strcat(filename, "convey_");
break;
case 6:
graycode_matrix(trans_r, trans_c, height, width); strcat(filename, "graycode_"); //sampling_matrix(trans_r, trans_c, height, width); //strcat(filename, "sampling_");
break;
case 7: if(width!=height) { printf("height%d!=width%d",height,width); return; }
baker_matrix(trans_r, trans_c, height, width); strcat(filename, "baker_");
break;
case 8:
logistic_matrix(trans_r, trans_c, height, width); strcat(filename, "logistic_");
break;
case 9:/*
sampling_matrix(trans_r, trans_c, height, width); strcat(filename, "sampling_");*/ random_matrix(trans_r, trans_c, height, width); strcat(filename, "random_");
break;
default:
break;
}
//+====================================================
int MASK_size,mask_half,SUM,SUMn;
int **count,*count_histg,**src_r,**src_c; int **countn,*count_histgn;
int mask_row,mask_col;
int X0,Y0;
int Xp,Yp;
int s; int r,c; float mean_n,mean_nn;
MASK_size = MASK_width*MASK_width; //模板大小
mask_half = (MASK_width - 1)/2; //模板宽度的一半
count = int_matrix(height, width);
count_histg = int_vector(MASK_size); countn = int_matrix(height, width);
count_histgn = int_vector(MASK_size); src_r = int_matrix(height, width);
src_c = int_matrix(height, width);/*--------------------------------------------------------------*//* double p_m,MEAN_n,p_0,p_1,p_2,p_3,p_4; MASK_size = MASK_width*MASK_width; p_m = (double)(MASK_size-1)/(width*height-1); MEAN_n = (double)(MASK_size-1)*(MASK_size-1)/(width*height-1); p_0 = pow((1-p_m),(MASK_size-1)); p_1 = (p_0/(1-p_m))*p_m*(MASK_size-1); p_2 = (p_1/(1-p_m))*p_m*(MASK_size-2)/2; p_3 = (p_2/(1-p_m))*p_m*(MASK_size-3)/3; p_4 = (p_3/(1-p_m))*p_m*(MASK_size-4)/4; printf("%dx%d : p_m = %f MEAN_n = %f p_0 = %f p_1 = %f p_2 = %f p_3 = %f p_4 = %f\n",MASK_width,MASK_width,p_m,MEAN_n,p_0,p_1,p_2,p_3,p_4);*/ char fname[64]; char str[25]; gcvt(MASK_width,5,str); strcpy(fname,"mask_"); strcat(fname, str); strcat(fname,".txt"); double p_m,MEAN_n,mean; int cc=0;/*----------------------------------------------------------------*/ fp1 = fopen(fname,"wb"); MASK_size = MASK_width*MASK_width; double p[MASK_size]; double rp[MASK_size]; p_m = (double)(MASK_size-1)/(width*height-1); MEAN_n = (double)(MASK_size-1)*(MASK_size-1)/(width*height-1); printf("%dx%d : p_m = %f MEAN_n = %f \n",MASK_width,MASK_width,p_m,MEAN_n); //fprintf(fp1,"%dx%d : p_m = %f MEAN_n = %f \n",MASK_width,MASK_width,p_m,MEAN_n); p[0] = pow((1-p_m),(MASK_size-1)); printf("p[0] = %f \n",p[0]); //fprintf(fp1,"p[0] = %f \n",p[0]); i = 0; fprintf(fp1,"%d %f \n",i,p[i]); mean = 0;/*--------------------------------------------------- for(i = 1;i < MASK_size;i ++) { p[i] = 0; p[i] = (p[i-1]/(1-p_m))*p_m*(MASK_size-i)/i; if(p[i] > 0.000001) { printf("p[%d] = %f \n",i,p[i]); //fprintf(fp1,"p[%d] = %f \n",i,p[i]); fprintf(fp1,"%d %f \n",i,p[i]); cc++; } mean = mean + i*p[i]; }/*---------------------------------------------------*//*---------------------------------------------------*/ for(i = 1;i < MASK_size;i ++) { p[i] = 0; //p[i] = (p[i-1]/(1-p_m))*p_m*(MASK_size-i)/i; p[i] = (p[i-1]/(1-p_m))*p_m*(MASK_size-i)/i; if(p[i] > 0.000001) { printf("p[%d] = %f \n",i,p[i]); //fprintf(fp1,"p[%d] = %f \n",i,p[i]); fprintf(fp1,"%d %f \n",i,p[i]); cc++; } mean = mean + i*p[i]; }/*---------------------------------------------------*/ printf("mean = %f\n\n",mean); fclose(fp1); double degree,ed1, ed2; double p_all = 0; degree = 0; ed1 = 0; ed2 = 0; for(i = 0;i < MASK_size;i ++) { degree += (double)fabs(i - MEAN_n)*p[i]; if(i - MEAN_n < 0.000001) ed1 += (double)(i - MEAN_n)*p[i]; if(i - MEAN_n > 0.000001) ed2 += (double)(i - MEAN_n)*p[i]; p_all += p[i]; } printf("p_all = %f\n",p_all); /*--------------------------------------------------------------- double pp_m,pMEAN_n,pmean; int pMASK_width,pMASK_size; double pdegree,ped1, ped2; double var,Var,Varp;fp1 = fopen("mask.txt","wb");for(pMASK_width = 3; pMASK_width < 39; pMASK_width += 2){ pMASK_size = pMASK_width*pMASK_width; double pp[pMASK_size]; pp_m = (double)(pMASK_size-1)/(width*height-1); pMEAN_n = (double)(pMASK_size-1)*(pMASK_size-1)/(width*height-1); printf("%dx%d : pp_m = %f pMEAN_n = %f \n",pMASK_width,pMASK_width,pp_m,pMEAN_n); fprintf(fp1,"%dx%d : pp_m = %f pMEAN_n = %f \n",pMASK_width,pMASK_width,pp_m,pMEAN_n); pp[0] = pow((1-pp_m),(pMASK_size-1)); printf("pp[0] = %f \n",pp[0]); i = 0; //fprintf(fp1,"pp[%d] = %f \n",i,pp[i]); fprintf(fp1," %d %f \n",i,pp[i]); pmean = 0; for(i = 1;i < pMASK_size;i ++) { pp[i] = 0; pp[i] = (pp[i-1]/(1-pp_m))*pp_m*(pMASK_size-i)/i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -