📄 addnoise.c
字号:
#include <tina/all_tina.h>#include "bmp.h"
#define MAXPATHLEN 64static char directory_name[MAXPATHLEN];static char file_name[MAXPATHLEN];static char pathname[MAXPATHLEN];
static void *pdir=0, *pfile=0;static int SCRAM_n = 1;static int percent_choice = 0;static Imrect *orig_im = NULL;static Imrect *dest_im = NULL;static Tv *tv = NULL;static Tv *tv1=NULL;static percent_choice_proc(int val){ percent_choice = 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 mypush_proc(void){ Imrect *srcIm,*srcIm0; int width, height;
Imregion *roi; int i,j; //BYTE pix; int pix; 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); 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); } mono_image_set(srcIm0);
stack_push(srcIm0, IMRECT, im_free);*/ orig_im = srcIm; tv_imrect2(tv, orig_im); stack_push(srcIm, IMRECT, im_free);}static Imrect* mypop_proc(void){ Imrect *srcIm; //BYTE pix; float pix; int type; if (stack_check_types(IMRECT, NULL) == false)
{
error("send-client : wrong types on stack", warning);
return;
} srcIm = (Imrect *) stack_pop(&type); return srcIm;}void addnoise_Trans(int nTrans)
{
Imrect *srcIm,*destIm,*tmpIm,*srcIm0,*srcbw,*destbw;
int width, height;
Imregion *roi; int i,j,k; int type;
//BYTE pix; int pix; char filenamesave[64]; char string[25]; char filename[64]; strcpy(filename,"result/addnoise/"); //strcat(filename,file_name); if (stack_check_types(IMRECT, NULL) == false)
{
error("addnoise : wrong types on stack", warning);
return;
} srcIm = (Imrect *) stack_pop(&type); //srcIm = read_image(); //srcIm = DrawRGB_proc();/* (void) strip_spaces(file_name); (void) strip_spaces(directory_name); (void) string_append(pathname, directory_name, "/", file_name, NULL); srcIm = BmpToImrect(pathname);*/
width = srcIm->width;
height = srcIm->height;
if (width != height)
{
error("addnoise:width != height", warning);
return;
}
roi = srcIm->region;
if (roi == NULL) return ;/*------------------------------------------------*/ int **trans_r, **trans_c;
trans_r = int_matrix(height, width);
trans_c = int_matrix(height, width); hilbert_matrix(trans_r, trans_c, height, width);
/*------------------------------------------------*/
printf("\n\n=== addnoise Transform begin: ===\n"); srcbw = im_alloc( height, width, roi, int_v ); destbw = im_alloc( height, width, roi, int_v ); destIm = 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(destIm, i, j, pix); IM_PIX_SET(srcbw, i, j, 0); } strcpy(filenamesave,filename); switch(percent_choice) { case 0: for(i = 128;i < 128 + 52;i ++) for(j = 100;j < 100 + 63; j ++) IM_PIX_SET(srcbw, i, j, 255);//5% strcat(filenamesave,"5%_h0.bmp"); strcat(filename,"5%_h"); break; case 1: for(i = 100;i < 100 + 78;i ++) for(j = 100;j < 100 + 126; j ++) IM_PIX_SET(srcbw, i, j, 255);//15% strcat(filenamesave,"15%_h0.bmp"); strcat(filename,"15%_h"); break; case 2:/*-------------------------------------------------------*/ for(i = 128;i < 128 + 128;i ++) for(j = 128;j < 128 + 128; j ++) IM_PIX_SET(srcbw, i, j, 255);//25%/*------------------------------------------------------- for(i = 64;i < 64 + 64;i ++) for(j = 64;j < 64 + 64; j ++) IM_PIX_SET(srcbw, i, j, 255);//25%,128*128/*-------------------------------------------------------*/ strcat(filenamesave,"25%_h0.bmp"); strcat(filename,"25%_h"); break; case 3: for(i = 30;i < 30 + 181;i ++) for(j = 50;j < 50 + 181; j ++) IM_PIX_SET(srcbw, i, j, 255);//50% strcat(filenamesave,"50%_h0.bmp"); strcat(filename,"50%_h"); break; case 4: for(i = 0;i < 0 + 256;i ++) for(j = 20;j < 20 + 192; j ++) IM_PIX_SET(srcbw, i, j, 255);//75% strcat(filenamesave,"75%_h0.bmp"); strcat(filename,"75%_h"); break; default: break; } ImrectToBMP8(srcbw,filenamesave); printf("saved the image :%s\n",filenamesave);
for( k = 0; k < SCRAM_n; k++)
{ for (i = 0; i < height ; i++)
{
for (j = 0; j< width ; j++)
{ IM_PIX_GET(srcbw, i, j, pix);
IM_PIX_SET(destbw, trans_r[i][j], trans_c[i][j], pix); IM_PIX_GET(srcIm, i, j, pix);
IM_PIX_SET(destIm, trans_r[i][j], trans_c[i][j], pix);
}
}
tmpIm = srcbw;
srcbw = destbw;
destbw = tmpIm; tmpIm = srcIm;
srcIm = destIm;
destIm = tmpIm; }/*----------------------Save the image --------------------------*/ gcvt(k,5,string); printf("string=%s\n",string); strcat(filename, string); strcpy(filenamesave,filename); strcat(filenamesave,".bmp"); ImrectToBMP8(srcbw,filenamesave); printf("saved the image :%s\n",filenamesave); for(i = 0; i < height; i ++) for(j = 0; j < width; j ++) { IM_PIX_GET(srcbw,i,j,pix); if(pix == 255) IM_PIX_SET(srcIm,i,j,255); } strcpy(filenamesave,filename); strcat(filenamesave,"_addnoise.bmp"); ImrectToBMP8(srcIm,filenamesave); printf("saved the image :%s\n",filenamesave);/*------------------------------------------------*/ dest_im = im_copy(srcbw); tv_imrect2(tv1, dest_im); //mono_image_set(srcIm0);
//stack_push(srcIm0, IMRECT, im_free); im_free(destbw); im_free(srcbw); im_free(destIm); free_int_matrix(trans_r, height);
free_int_matrix(trans_c, height); printf("=== addnoise transform complete! ===\n");
}
static void fulldraw(Tv *tv){ tv_imrect2(tv, orig_im);}static void fulldraw1(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);}void addnoise_tool(int x, int y)
{
static void *tool = NULL;
static void tv_choice_proc(); if (tool)
{
tw_show_tool(tool);
return;
}
tool = (void *)tw_tool("addnoise Scrambling 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/addnoise/Lena.bmp"); tv = tv_create("addnoise original");
tv1 = tv_create("addnoise scrambled");
tw_choice("Tv choice", tv_choice_proc, 0, "original","scrambled", NULL); tv_set_fulldraw(tv, fulldraw); tv_set_fulldraw(tv1,fulldraw1); 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_newrow(); tw_choice("% choice", percent_choice_proc, 0, "5%","15%","25%","50%","75%", NULL); tw_newrow(); tw_iglobal("(Hilbert)Scrambling times = ", &SCRAM_n, 5);
tw_newrow();
tw_button("addnoise", addnoise_Trans,NULL); tw_button("push",mypush_proc,NULL); tw_button("pop",mypop_proc,NULL); tw_newrow(); tw_newrow();
tw_end_tool();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -