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

📄 receive.c

📁 图像置乱代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	printf("hwm\n");	strcpy(filename0,"_hwm");	for(i = 0;i < height; i ++)		for(j = 0;j < width; j ++)		{			pix = im_get_pixf(srcIm0,i,j);			adapt = 1;			//if(fabs(pix - cutpix) < f )//lost point			if(flag[i][j]==0)			{				m_count = 0;				gray_sum = 0.0;				hws = 0.0;				while(m_count < MCOUNT )//at least have MCOUNT points in the mask				{					m_count = 0;					gray_sum = 0.0;					hws = 0.0;					for(t = i - adapt; t <= i + adapt; t ++)						for(h = j - adapt; h <= j + adapt; h ++)						{							if((t<0)||(t>=height)||(h<0)||(h>=width))								continue;							pixm = im_get_pixf(srcIm0,t,h);							//if(fabs(pixm - cutpix) > f)//orig point							if(flag[t][h]==1)//orig pexel							{								gray_sum += ho[(int)pixm]*pixm;								hws += ho[(int)pixm];								m_count ++;							}						}					if(m_count < MCOUNT)						adapt ++;				}				pixm = (float)(gray_sum/hws);//mean				count_adapt[adapt] ++;				im_put_pixf(pixm,destIm,i,j);			}			else 			{				im_put_pixf(pix,destIm,i,j);				count_adapt[0] ++;			}		}/*---------------------------------------------------------------------*/			break;
		default:
			break;
    	}/*----------------------------------------------*/	gcvt(MCOUNT,5,string);	strcat(filename0, string);	//strcat(filename, filename0);	char filename1[64];		char filename2[64];	char filename3[64];	char filenametxt[64];	strcpy(filename1,"result/receive/repair");//filename without change	gcvt(pol,5,string);	strcat(filename1, string);	strcat(filename1,filename0);	strcpy(filename2,filename1);	strcpy(filename3,filename1);	strcpy(filenametxt,filename1);	strcat(filename1,".bmp");	ImrectToBMP8(destIm,filename1);	strcat(filenametxt,".txt");	FILE *fp;	fp = fopen(filenametxt,"wb");/*----------------------------------------------*/	for(i = 0;i < 25; i ++)		if(count_adapt[i] != 0)		{			printf("count_adapt[%d] = %d\n",i,count_adapt[i]);			fprintf(fp,"count_adapt[%d] = %d\n",i,count_adapt[i]);		}/*----------------------------------------------*/	int count[256];	for(i = 0;i < 256; i ++)		count[i] = 0;	float mse = 0.0 ,psnr = 0.0 ,mae = 0.0, nmse = 0.0 ,op = 0.0;	for(i = 0; i < height; i ++)		for(j = 0; j < width; j ++)		{			IM_PIX_GET(destIm, i, j, pixb);			IM_PIX_GET(comp_orig, i, j, pixa);			pix = fabs(pixa - pixb);			IM_PIX_SET(dest_a_b, i, j, pix);			//printf("%f,%f,%f\n",pixa,pixb,pix);					count[(int)pix] ++;			IM_PIX_SET(dest_c,i,j,255 - pix);/*			if(pix < 40)			{				IM_PIX_SET(dest_c,i,j,255 );			}			else 			{				IM_PIX_SET(dest_c,i,j,0);			}*/			mse += pix*pix;			mae += pix;			op += pixa*pixa;		}/*----------------------------------------------	for(i = 0;i < 256; i ++)		if(count[i] != 0)		{			printf("count[%d] = %d\n",i,count[i]);			fprintf(fp, "count[%d] = %d\n",i,count[i]);		}/*----------------------------------------------*/	nmse = mse / op;	mse = mse/(height*width);	psnr = 10*log10(255*255/mse);	mae = mae/(height*width);	printf("Percent       MSE       PSNR          MAE        NMSE   \n");	printf("%f   %f   %f   %f   %f\n", (float)pol/100, mse, psnr, mae, nmse);	//fprintf(fp, "MSE = %f , PSNR = %f , MAE = %f , NMSE = %f\n", mse, psnr, mae, nmse);	fprintf(fp, "%f  %f  %f  %f  %f\n", (float)pol/100, mse, psnr, mae, nmse);	fclose(fp);/*------------------------------------------------	strcat(filename2,"_comp.bmp");	ImrectToBMP8(dest_a_b,filename2);	strcat(filename3,"_comp_r.bmp");	ImrectToBMP8(dest_c,filename3);/*------------------------------------------------*/	im_free(dest_a_b);	im_free(dest_c);/*------------------------------------------------*/	repair_im = im_copy(destIm);	tv_imrect2(tv2, repair_im);/*------------------------------------------------	mono_image_set(destIm);
	stack_push(destIm, IMRECT, im_free);	im_free(srcIm0);/*------------------------------------------------*/	free_int_matrix(flag, height);	mono_image_set(srcIm0);
	stack_push(srcIm0, IMRECT, im_free);	im_free(destIm);	printf("\n=== %s complete! ===\n",filename0);	//strcpy(filename,filename_in);	im_free(adaptim);}static void compare_proc(void){/*----------------Pop the org_image from stack-------------------*/	Imrect *orig_a;	Imrect *orig_b;	Imrect *dest_a_b;	Imrect *dest_c;    	int     type;	int width, height;
	float pix,pixa,pixb;
	Imregion *roi;	int i,j;	if (stack_check_types(IMRECT, NULL) == false)
	{		printf("pop 图像b 失败!\n");
		error("Motion_proc : wrong types on stack", warning);
		return;
	}
	orig_b = (Imrect *) stack_pop(&type);	printf("pop 图像b 成功!\n");	if (stack_check_types(IMRECT, NULL) == false)
	{		printf("pop 图像a 失败!\n");
		error("Motion_proc : wrong types on stack", warning);
		return;
	}
	orig_a = (Imrect *) stack_pop(&type);	printf("pop 图像a 成功!\n");/*-----------------------------------------------------------------------------*/	width = orig_a->width;
    	height = orig_a->height;
	roi = orig_a->region;
	if (roi == NULL) return ;	dest_a_b = im_alloc( height, width, roi, float_v );	dest_c = im_alloc( height, width, roi, float_v );	int count[256];	for(i = 0;i < 256; i ++)		count[i] = 0;	for(i = 0; i < height; i ++)		for(j = 0; j < width; j ++)		{			IM_PIX_GET(orig_b, i, j, pixb);			IM_PIX_GET(orig_a, i, j, pixa);			pix = fabs(pixa - pixb);			IM_PIX_SET(dest_a_b, i, j, pix);			//printf("%f,%f,%f\n",pixa,pixb,pix);					count[(int)pix] ++;			IM_PIX_SET(dest_c,i,j,255 - pix);/*			if(pix < 40)			{				IM_PIX_SET(dest_c,i,j,255 );			}			else 			{				IM_PIX_SET(dest_c,i,j,0);			}*/		}	for(i = 0;i < 256; i ++)		if(count[i] != 0)			printf("count[%d] = %d\n",i,count[i]);	char filename1[64];	strcpy(filename1,"result/receive/compare/cmean1.bmp");	ImrectToBMP8(dest_a_b,filename1);	ImrectToBMP8(dest_c,"result/receive/compare/mean1c.bmp");	im_free(dest_a_b);	im_free(dest_c);	//mono_image_set(dest_a_b);
	//stack_push(dest_a_b, IMRECT, im_free);}static void test_proc(void){/*	int i;	float *data;	float pixm;	data = fl_vector(11);	for(i = 0; i < 11; i ++)		data[i] = i;	pixm = get_median(data,11);	printf("median=%f\n",pixm);	data[7]=9;	pixm = get_mode(data,11);	printf("mode= %f\n",pixm);	free_fl_vector(data);*/	Imrect *srcIm,*srcIm0;	float pix;	int type;	int width, height;	Imregion *roi;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("receive-client : wrong types on stack", warning);
		return;
	}	srcIm = (Imrect *) stack_pop(&type);	width = srcIm->width;
    	height = srcIm->height;
	roi = srcIm->region;
	if (roi == NULL) return ;	int i,j;	srcIm0 = im_alloc( height, width, roi, float_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);		}	ImrectToBMP8(srcIm0,"result/receive/compare/test.bmp");	//im_free(srcIm0);	mono_image_set(srcIm0);
	stack_push(srcIm0, IMRECT, im_free);}static void fulldraw(Tv *tv){     tv_imrect2(tv, orig_im);}static void fulldraw1(Tv *tv){     tv_imrect2(tv, contra_scram_im);}static void fulldraw2(Tv *tv){     tv_imrect2(tv, repair_im);}static void tv_choice_proc(choice)
int     choice;
{
    switch (choice)
    	{
    	case 0: tv_set_next(tv);//original
		break;
    	case 1: tv_set_next(tv1);//contra-transformation
		break;    	case 2: tv_set_next(tv2);//repair
		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            receive_client_tool(int x, int y)
{
	static void *tool = NULL;	if (tool)
	{
		tw_show_tool(tool);
		return;
	}
	tool = (void *)tw_tool("receive-client 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/receive/receive.bmp");	tv = tv_create("receive-client original");
     	tv1 = tv_create("receive-client contra-thansformation");     	tv2 = tv_create("receive-client repair");
        tw_choice("Tv choice", tv_choice_proc, 0, "original","contra-thansformation","repair",NULL);	tv_set_fulldraw(tv, fulldraw);	tv_set_fulldraw(tv1,fulldraw1);	tv_set_fulldraw(tv2,fulldraw2);	/*---------------------------*/  	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("show",myshow_proc,NULL);
	tw_button("save",mysave_proc,NULL);	tw_newrow();	tw_choice("Cut %", cut_choice_proc, 0,\
              "25%", "50%", "75%-L_up", "75%-R_up", "75%-L_down", "75%-R_down", "specify",  NULL);	tw_newrow();	tw_iglobal("start point:h= ", &START_h, 5);	tw_iglobal("w= ", &START_w, 5);	tw_iglobal("o-height=", &ORIG_height, 5);	tw_iglobal("o-width=", &ORIG_width, 5);	tw_newrow();	tw_button("use the keys to rebuild",rebuild_proc,NULL);	tw_newrow();   	tw_label("----------------------------------------------------------------");	tw_newrow();
	tw_choice("Scrambling Method:", scram_choice_proc, 0,\
              "Fibonacci", "Arnold", "QATLIG", "Hilbert", "Convey", "Latin", "Zigzag", "Baker", "Logistic", "Random",  NULL);
	tw_newrow();	tw_iglobal("Scrambling times = ", &SCRAM_n, 5);	tw_newrow();	tw_button("Contra-Transformation",Contra_Trans_proc,NULL);   	tw_label("              ");	tw_button("reset",reset_proc,NULL);	tw_newrow();   	tw_label("----------------------------------------------------------------");	tw_newrow();	tw_choice("repair method:", repair_choice_proc, 0,\
              "mean", "median", "mode", "w-mean","hwm", NULL);         tw_newrow();	tw_choice("show:", show_choice_proc, 0,\
              "result", "step by step", NULL);	tw_newrow();	tw_iglobal("not less than ", &MCOUNT, 5);	tw_label("original points in the mask ");
	tw_newrow();	tw_button("repair",repair_proc,NULL);	tw_button("compare",compare_proc,NULL);	tw_button("test",test_proc,NULL);	tw_button("nhwfm", nhwfm_proc, NULL);
	tw_end_tool();
}

⌨️ 快捷键说明

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