⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c~

📁 图像置乱代码
💻 C~
📖 第 1 页 / 共 2 页
字号:
		srcIm0 = destIm;
		destIm = tmpIm;	}/*----------------------Save the image as .gif--------------------------*/	gcvt(k,5,string);	printf("scrambled %s times\n",string);	strcat(filename, filename0);	strcat(filename, string);/*------------------------------------------------*/	    	Tv *tvd=NULL;	void *displayd;	displayd=(void *)display_tool(20+256+15,20,256,256);    	tvd=(Tv *)tv_create("DestRGB");    	tv_install(tvd, displayd);
    	//tv_set_fulldraw(tvd, draw_DestRGB);	Ipos pos1;	int t;	int x,y;	tv_set_color(tvd, green);	for(i = 0;i < 256;i ++)		for(j = 0;j < 256;j ++)		{			pos1=ipos(i,j);			tv_point(tvd,pos1);			}	tv_set_color(tvd, red);	for(i = 0;i < height; i ++)		for(j = 0;j < width; j++)		{			IM_PIX_GET(srcIm0, i, j, pix);			if(pix == 49)			{				for(x = 0 + i*32;x < 32 + i*32;x ++)					for(y = 0 + j*32;y < 32 + j*32;y ++)					{						pos1=ipos(x,y);						tv_point(tvd,pos1);						}			}					}	tv_set_color(tvd, blue);	for(i = 1; i < 8;i ++)	{		t = i*32 - 1;		tv_linexy(tvd, t, 0, t, 255);		tv_linexy(tvd, 0, t,255,t);	}
   	tv_repaint(tvd);	dest_im = im_copy(srcIm0);	tv_imrect2(tv1, dest_im);	mono_image_set(srcIm0);
	stack_push(srcIm0, IMRECT, im_free);	im_free(srcIm0);	im_free(destIm);	free_int_matrix(trans_r, height);
	free_int_matrix(trans_c, height);	free_int_matrix(dest_r,height);	free_int_matrix(dest_c,height);	printf("=== %stransformatioin complete! ===\n",filename0);	}static void Contra_Trans_proc(void){	Imrect *srcIm,*destIm,*tmpIm,*srcIm0;
	int width, height;
	Imregion *roi;	int i,j,k;	int type;
	//BYTE pix;	int pix;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("Contra_Trans : 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 ;	orig_im = im_copy(srcIm);	tv_imrect2(tv, orig_im);	char filename0[64];	char string[25];	strcpy(filename0,"+Contra_");/*------------------------------------------------*/	int **trans_r, **trans_c;
	trans_r = int_matrix(height, width);
	trans_c = int_matrix(height, width);    	switch( scram_method )
    	{
    		case 0:
    			r_fibonacci_matrix(trans_r, trans_c, height, width);;			strcat(filename0, "fibonacci_");
			break;
    		case 1:
    			r_arnold_matrix(trans_r, trans_c, height, width);			strcat(filename0, "arnold_");
			break;
    		case 2:
    			r_qatlig_matrix(trans_r, trans_c, height, width);			strcat(filename0, "qatlig_");
			break;
    		case 3:
			r_hilbert_matrix(trans_r, trans_c, height, width);			strcat(filename0, "hilbert_");
			break;
		case 4:
			r_convey_matrix(trans_r, trans_c, height, width);			strcat(filename0, "convey_");
			break;
    		case 5:
			r_latin_matrix(trans_r, trans_c, height, width);			strcat(filename0, "latin_");
			break;
		case 6:
    			r_graycode_matrix(trans_r, trans_c, height, width);			strcat(filename0, "graycode_");
			break;
		case 7:
    			r_baker_matrix(trans_r, trans_c, height, width);			strcat(filename0, "baker_");
			break;
		case 8:
    			r_logistic_matrix(trans_r, trans_c, height, width);			strcat(filename0, "logistic_");
			break;
		case 9:
			r_sampling_matrix(trans_r, trans_c, height, width);			strcat(filename0, "sampling_");
			break;
		default:
			break;
    }/*------------------------------------------------*/
	printf("\n=== %sTransformation begin: ===\n",filename0);	destIm = im_alloc( height, width, roi, int_v );	srcIm0 = im_alloc( height, width, roi, int_v );	for(i = 0;i < height; i ++)		for(j = 0;j < width; j++)		{			IM_PIX_GET(srcIm, i, j, pix);
			IM_PIX_SET(srcIm0, i, j, pix);		}
	for( k = 0; k < SCRAM_n; k++)
	{			for (i = 0; i < height  ; i++)
		{
			for (j = 0; j< width ; j++)
			{								IM_PIX_GET(srcIm0, i, j, pix);
				IM_PIX_SET(destIm, trans_r[i][j], trans_c[i][j], pix);
			}
		}
 		tmpIm = srcIm0;
		srcIm0 = destIm;
		destIm = tmpIm;	}/*----------------------Save the image as .gif--------------------------*/	gcvt(k,5,string);	printf("Contra_scrambled %s times\n",string);	strcat(filename, filename0);	strcat(filename, string);/*------------------------------------------------*/	dest_im = im_copy(srcIm0);	tv_imrect2(tv1, dest_im);	mono_image_set(srcIm0);
	stack_push(srcIm0, IMRECT, im_free);	im_free(destIm);	free_int_matrix(trans_r, height);
	free_int_matrix(trans_c, height);	printf("=== %stransformatioin complete! ===\n",filename0);}void noise_proc(void){	Imrect *noise_im;	int height,width;	int i,j,count,u,v;	double  M;	height = 256;	width = 256;	M = height*width;	printf("%f\n",M);	noise_im = im_alloc( height, width, NULL, int_v );	if(noise_im == NULL)		printf("im_alloc failed!\n");	count = 0;	for (i = 0; i < height; i++)
    	{
        	for(j = 0; j < width; j++)
        	{				IM_PIX_SET(noise_im, i, j, 0);
        	}
    	}	long entier,r;	//r = (int)uniform_random(0.0, M, R0, LAMBDA,MOD);	double x = (double)R0/(double)MOD; /* set the initial value.*/
   	for (i = 0; i < (int)M/2; i++)
    	{			//r = (int)uniform_random(0.0, M, 0, LAMBDA,MOD);		x *= (double)LAMBDA;		entier = (x > 0.0)?		floor(x)  :  ceil(x);		x -= (double)entier;
		r = floor(height * width * x);		u = r / 256;
		v = r % 256;		printf("--%d(%d,%d)",r,u,v);		if(u<0||u>M||v<0||v>M)		{			printf("(%d,%d)",u,v);			printf("!!!out");			continue;		}
		IM_PIX_SET(noise_im, u, v, 255);		count ++;    	}	printf("255 count = %d,  %f",count,(float)count/(height*width));	ImrectToBMP8(noise_im, "noise.bmp");	im_free(noise_im);}static void compute_p_proc(void){/*----------------------------------------------------------------*/	int MASK_width = 3;	int width = 8;	int height = 8;	double p_m,MEAN_n,mean;	int cc=0;	int MASK_size;	MASK_size = MASK_width*MASK_width;	double p[MASK_size];	double degree = 0;	double p_all = 0;	int i;	//p_m = (double)(MASK_size-1)/(width*height);	//p_m = (double)(MASK_size)/(width*height);	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);	p[0] = pow((1-p_m),(MASK_size-1));	printf("p[0] = %f  \n",p[0]);	i = 0;	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]);			cc++;		}		mean = mean + i*p[i];	}	printf("%dx%d : p_m = %f  MEAN_n = %f \n",MASK_width,MASK_width,p_m,MEAN_n);	printf("mean = %f\n\n",mean);	for(i = 0;i < MASK_size;i ++)	{		degree += (double)fabs(i - MEAN_n)*p[i];		p_all += p[i];	}	printf("degree = %f   p_all = %f\n",degree,p_all);}static void fulldrawo(Tv *tv){     tv_imrect2(tv, orig_im);}static void fulldrawd(Tv *tv){     tv_imrect2(tv, dest_im);}static void tv_choice_proc(choice)
int     choice;
{
    switch (choice)
    	{
    	case 0: tv_set_next(tv);
		break;
    	case 1: tv_set_next(tv1);
		break;
    	default:error("tv_choice_proc: unknown choice\n", warning);
		break;
    	}}static void scan_proc(void){    scan_files(directory_name,file_name);    tw_sglobal_reset(pdir);    tw_sglobal_reset(pfile);}static void tool_proc(void)
{
    static int x = 200, y = 0;
    static int xr = 0, yr = 0;

    tv_tool(x+xr, y+yr);
    xr += 275;
    yr += 0;
    if (x+xr>780)
    {
       xr = yr = 0;
       y += 50;
    }
    if (y>400) y = 200;
}

/********** Tool creation **********/
void            test_tool(int x, int y)
{
	static void *tool = NULL;	if (tool)
	{
		tw_show_tool(tool);
		return;
	}
	tool = (void *)tw_tool("Image test tool", x, y);
    	/* Initialise pathname from environment variable (or #define) */    	(void) environ_pathname_get(directory_name, file_name,				"TINA_IMAGE_DEFAULT",				"/home/wzz/newimscramdegree/result/test/10.bmp");
        tw_choice("Tv choice", tv_choice_proc, 0, "original","scrambled", NULL);	tv = tv_create("test original");
     	tv1 = tv_create("test scrambled");	tv_set_fulldraw(tv, fulldrawo);	tv_set_fulldraw(tv1,fulldrawd);	/*---------------------------*/  	tw_newrow();
	tw_label("Display");
	tw_button("New Tvtool", tool_proc, NULL);	/*---------------------------*/ 	tw_newrow();  	pdir = (void *) tw_sglobal("Directory:", directory_name, 32);    	tw_button("scan", scan_proc, NULL);  	tw_newrow();  	pfile = (void*) tw_sglobal("File:", file_name, 32);  	tw_newrow();	/*---------------------------*/        tw_choice("input image choice", image_choice_proc, 0, "BMP","GIF", NULL);   	tw_label("              ");	tw_button("push",mypush_proc,NULL);	tw_button("pop",mypop_proc,NULL);
	tw_button("save",mysave_proc,NULL);	tw_newrow();	strcpy(filename,"result/test/");	strcat(filename,file_name);
	tw_choice("Scrambling Method:", scram_choice_proc, 0,\
              "Fibonacci", "Arnold", "QATLIG", "Hilbert", "Convey", "Latin", "GrayCode", "Baker", "Logistic", "Sampling",  NULL);
	tw_newrow();	tw_iglobal("Scrambling times = ", &SCRAM_n, 5);	tw_newrow();	tw_button("Transformation",Trans_proc,NULL);	tw_button("Contra-Transformation",Contra_Trans_proc,NULL);	tw_button("reset",reset_proc,NULL);	//tw_button("DrawRGB",DrawRGB_proc,NULL);	tw_button("showtv",show_tv_proc,NULL);	tw_newrow();	tw_button("nhwfm", nhwfm_proc, NULL);	tw_button("noise", noise_proc, NULL);	tw_button("compute_p", compute_p_proc, NULL);	tw_newrow();
	tw_end_tool();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -