📄 receive.c
字号:
for(i=0;i<256;i++) { for(j=0;j<256;j++) { IM_PIX_GET(srcIm0, i, j, pix); if(fabs(pix - 254.56789) > 0.00001) { IM_PIX_SET(crackim, index/128, index%128, pix); index++; printf(" (%d,%d)%d ",i,j,index); if(index==128*128) break; } } if(index==128*128) break; } ImrectToBMP8(crackim,"crackim.bmp"); im_free(crackim);/*------------------------------------------------*/ contra_scram_im = im_copy(srcIm0); tv_imrect2(tv1, contra_scram_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",filename);}static void repair_proc(void){ Imrect *srcIm,*destIm,*srcIm0;
int width, height;
Imregion *roi; int i,j; int type; float pix; float pixa,pixb; //char filename_in[64]; //strcpy(filename_in,filename); if (stack_check_types(IMRECT, NULL) == false)
{
error("mean_repair : wrong types on stack", warning);
return;
} srcIm = (Imrect *) stack_pop(&type);
width = srcIm->width;
height = srcIm->height;
roi = srcIm->region;
if (roi == NULL) return ; Imrect *comp_orig = NULL,*dest_a_b = NULL,*dest_c = NULL; //Lenaorig = BmpToImrect("/home/wzz/newimscramdegree/result/receive/Lena.bmp"); //Lenaorig = ReadGIF("/home/wzz/newimscramdegree/result/receive/Lena.gif",1); //comp_orig = BmpToImrect("/home/wzz/newimscramdegree/result/g256.bmp"); comp_orig = ReadGIF("/home/wzz/newimscramdegree/result/Lena.gif",1); //comp_orig = ReadGIF("/home/wzz/newimscramdegree/result/newscramdegree/Lena_512x512.gif",1); if (comp_orig == NULL) { printf("read image error."); return; } destIm = im_alloc( height, width, roi, float_v ); srcIm0 = im_alloc( height, width, roi, float_v ); dest_a_b = im_alloc( height, width, roi, float_v ); dest_c = 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); } printf("start repair!\n"); char filename0[64]; char string[25]; //strcpy(filename0,"_repair"); //float cutpix = 254.56789; float cutpix = 255; int adapt =1; int m_count =0; float gray_sum = 0.0; float pixm,pixm1,pixm2,pixm3; int t,h; int count_adapt[25]; const float f = 0.00001; float *neighbor,*togetmed; int n = 0; int r; int **flag; int w,ws = 0; int lp = 0; int pol; int hn[256]; float ho[256]; float hws = 0.0; for(i = 0;i < 25; i ++) count_adapt[i] = 0; flag = int_matrix(height, width); for(i = 0;i < 256; i ++) hn[i] = 0; for(i = 0;i < height; i ++) for(j = 0;j < width; j ++) { pix = im_get_pixf(srcIm0,i,j); if(fabs(pix - cutpix) < f ) { flag[i][j] = 0; lp ++; } else { hn[(int)pix]++; flag[i][j] = 1; } } pol = (int)((float)lp/(float)(height*width)*100+0.5); printf("propability of lost pexel : %f \n",(float)pol/100); for(i = 0;i < 256; i ++) { ho[i] = (float)hn[i]/((1 - (float)pol/100)*height*width); }/*-------------------------------------------------------------------------*/ Imrect *adaptim; int v1,v2; Tv *tvo=NULL; void *displayo;
displayo=(void *)display_tool(20,20,256,256);
tvo=(Tv *)tv_create("show adapt");
tv_install(tvo, displayo); adaptim = im_alloc( 256, 256, NULL, int_v );
//tv_set_fulldraw(tvo, fulldrawadapt);
//tv_repaint(tvo);/* Ipos pos1; tv_set_color(tvo, green); for(i = 0;i < 256;i ++) for(j = 0;j < 256;j ++) { pos1=ipos(i,j); tv_point(tvo,pos1); }*/ for(i = 0;i < 256;i ++) for(j = 0;j < 256;j ++) { IM_PIX_SET(adaptim, i, j, 255); }/*-------------------------------------------------------------------------*/ switch( repair_method )
{
case 0:/*--------------------------------mean-------------------------------------*/ printf("mean\n"); strcpy(filename0,"_mean"); 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; while(m_count < MCOUNT )//at least have MCOUNT points in the mask { m_count = 0; gray_sum = 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) { gray_sum += pixm; m_count ++; } } if(m_count < MCOUNT) adapt ++; } pixm = (float)(gray_sum/m_count);//mean count_adapt[adapt] ++; im_put_pixf(pixm,destIm,i,j); } else { im_put_pixf(pix,destIm,i,j); count_adapt[0] ++; } }/*---------------------------------------------------------------------*/
break;
case 1:/*------------------------------median---------------------------------------*/ printf("median\n"); strcpy(filename0,"_median"); 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; while(m_count < MCOUNT )//at least have MCOUNT points in the mask { m_count = 0; gray_sum = 0.0; n = (2*adapt+1)*(2*adapt+1); neighbor = fl_vector(n); 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) { neighbor[m_count]= pixm; m_count ++; } } if(m_count < MCOUNT) { adapt ++; free_fl_vector(neighbor); } } togetmed = fl_vector(m_count); for(r = 0;r < m_count;r ++) togetmed[r] = neighbor[r]; free_fl_vector(neighbor); pixm = get_median(togetmed,m_count);//median count_adapt[adapt] ++; im_put_pixf(pixm,destIm,i,j); free_fl_vector(togetmed); } else { im_put_pixf(pix,destIm,i,j); count_adapt[0] ++; } }/*----------------------------------------------------------------------------*/
break;
case 2:/*-------------------------------mode--------------------------------------*/ /* [Statistics] The value or item occurring most frequently in a series of observations or statistical data*/ printf("mode\n"); strcpy(filename0,"_mode"); 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; while(m_count < MCOUNT )//at least have MCOUNT points in the mask { m_count = 0; gray_sum = 0.0; n = (2*adapt+1)*(2*adapt+1); neighbor = fl_vector(n); 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) { neighbor[m_count]= pixm; m_count ++; } } if(m_count < MCOUNT) { adapt ++; free_fl_vector(neighbor); } } togetmed = fl_vector(m_count); for(r = 0;r < m_count;r ++) togetmed[r] = neighbor[r]; free_fl_vector(neighbor); pixm = get_mode(togetmed,m_count);//mode count_adapt[adapt] ++; im_put_pixf(pixm,destIm,i,j); free_fl_vector(togetmed); } else { im_put_pixf(pix,destIm,i,j); count_adapt[0] ++; } }/*--------------------------------------------------------------------------*/
break; case 3:/*-------------------------------w-mean-------------------------------------*/ printf("w-mean\n"); strcpy(filename0,"_w-mean"); 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; ws = 0; while(m_count < MCOUNT )//at least have MCOUNT points in the mask { m_count = 0; gray_sum = 0.0; ws = 0;/*-----------------------------------------------------------------------------*/ if(show_choice==1) { getchar(); printf("(%d,%d) adapt=%d %dx%d",i,j,adapt,2*adapt+1,2*adapt+1); }/*-----------------------------------------------------------------------------*/ for(v1 = 0;v1 < 256;v1 ++) for(v2 = 0;v2 < 256;v2 ++) { IM_PIX_SET(adaptim, v1, v2, 255); } for(v1 =0;v1 < (adapt*2+1)*10; v1++ ) { IM_PIX_SET(adaptim, v1, (adapt*2+1)*10, 0); } for(v1 =0;v1 < (adapt*2+1)*10; v1++ ) { IM_PIX_SET(adaptim, (adapt*2+1)*10,v1, 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;/*-----------------------------------------------------------------------------*/ if(t==i&&h==j) { for(v1 = 0; v1 <10; v1++) for(v2 = 0; v2 <10; v2++) { IM_PIX_SET(adaptim, (adapt-i+t)*10+v1, (adapt-j+h)*10+v2, 211); } }/*-----------------------------------------------------------------------------*/ pixm = im_get_pixf(srcIm0,t,h); //if(fabs(pixm - cutpix) > f)//orig point if(flag[t][h]==1)//orig pexel { w = adapt+1-IMAX(abs(i-t),abs(j-h)); gray_sum += w*pixm; ws += w; m_count ++;/*-----------------------------------------------------------------------------*/ for(v1 = 0; v1 <10; v1++) for(v2 = 0; v2 <10; v2++) { IM_PIX_SET(adaptim, (adapt-i+t)*10+v1, (adapt-j+h)*10+v2, 0); }/*-----------------------------------------------------------------------------*/ } } if(m_count < MCOUNT) adapt ++; tv_imrect2(tvo, adaptim); tv_repaint(tvo); } pixm = (float)(gray_sum/ws);//mean count_adapt[adapt] ++; im_put_pixf(pixm,destIm,i,j); } else { im_put_pixf(pix,destIm,i,j); count_adapt[0] ++; } }/*---------------------------------------------------------------------*/ break; case 4:/*-------------------------------hwm-------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -