EV WM SETFOCUS. EV_WM_DRAWCLIPBOARD EV_WM_DESTROY END_RESPONSE_TABLE: //****agent search**// //***小波变换菜单围avelet***/ /**原图象存在1ena.bmp**/ 后,分解图象存在1 enawt.b即*/ /**重建图象存在1 enaiwt.bp****/ void TBmpViewWindow:CmAgent() char ss[51 :ActiveAgent=5:SearchNum=0: AgentLife=2: SearchTime=0: for(i=0:i<AgentNum:i++)(Agent[i][O]=5*i+1:Agent[i][1]=5*i+1:isAgentAlive[i]=1:} MessageBox("ss","ss",MB_OK): if(pMemDC) for(x=0:x32:x++) for(y=0:y<32:y+ Image[x][y]=(unsigned short)pMemDC->GetPixel(x,y): 2 img[il[il=ffi]ril: while(1){ MessageBox("ss","ss",MB OK) if(ActiveAgent<0)break: for(i-0:i<AgentNum:i+) if(isAgentAlive[i]==1) x=Agent[i][O]:y=Agent [i][1]: if(Image[x][y]- 0) SolutionX[SearchNum]=x:SolutionY[SearchNum]=y: Image[x][v]=255://***marking this point pMemDC->SetPixel(x.y (unsigned char)Image[x][y]) AdjustScroller( SearchNum+=1: //**judge direction**// if(x+1)<32k&Image[x+1][y]=0){x=x+1:Agent[i][0]=x:】
EV_WM_SETFOCUS, EV_WM_DRAWCLIPBOARD, EV_WM_DESTROY, END_RESPONSE_TABLE; //****agent search******// //****小波变换菜单 Wavelet*******// //****原图象存在 lena.bmp***// //****运行后,分解图象存在 lenawt.bmp******// //****重建图象存在 lenaiwt.bmp***********// void TBmpViewWindow::CmAgent() { char ss[5]; int i,j,k,x,y; AgentNum=5;ActiveAgent=5;SearchNum=0; AgentLife=2; SearchTime=0; for(i=0;i<AgentNum;i++){Agent[i][0]=5*i+1;Agent[i][1]=5*i+1;isAgentAlive[i]=1;} // MessageBox("ss","ss",MB_OK); if(pMemDC) { for(x=0;x<32;x++) for(y=0;y<32;y++) Image[x][y]=(unsigned short)pMemDC->GetPixel(x,y); // img[i][j]=f[i][j]; while(1){ MessageBox("ss","ss",MB_OK); if(ActiveAgent<=0)break; for( i=0;i<AgentNum;i++) { if(isAgentAlive[i]==1) { x=Agent[i][0];y=Agent[i][1]; if(Image[x][y]== 0) { SolutionX[SearchNum]=x;SolutionY[SearchNum]=y; Image[x][y]=255;//***marking this point pMemDC->SetPixel(x,y, (unsigned char)Image[x][y]); AdjustScroller(); SearchNum+=1; //**judge direction**// if((x+1)<32&&Image[x+1][y]==0){x=x+1;Agent[i][0]=x;}
else if((x-1)>=0 &Image[x-1][y]==0)(x=x-1:Agent[i][o]=x: else if((y-1)mg[x][y-1]-0)(y-y-1:Agent[i][]-y:) else if((y+1)<32 Image[x][y+1 -0)y-y+1:Agent[i][1]=y: else {isAgentAlive[i]=0:ActiveAgent-=1: else //iudge direction**// if(Gx+1)<32kIm阳 e[x+1][y]=-0)(x=x+1:Agent[i][O]=x:] else if((x-1)>=0&Image [x-1][y]==0)(x=x-1:Agent[i][O]=x: else if((y-1)>=0&&Image[x][y-1]==0)(y=y-1:Agent [i][1]=y: else if((y+1)<32&&Image[x][y+1]==0)(y=y+1:Agent[i][1]=y:} else fisAgentAliveri]=0:ActiveAgent-=1: SearchTime++ //**end if isAgentAlive==1 1//**end for }//**end while sprintf(ss,d",SearchTime) Mes sageBox(ss,"Total Search times",MB_OK): void unsigned i,j,k;int xs,ys; unsigned char buf[SIZE+1],buf1[1078]: FILE *inputfile,*mfile,*outputfile: inputfile=fopen("lena.bmp"rb) if(!inputfile) MessageBox("Cannot open file lena.raw",GetApplication()->GetName(), MB_OK) Closewindow (0) mfile=fopen("lenawt.bmp","wb"); if(!mfile) MessageBox("Cannot open file lenawt.raw",GetApplication()->GetName(), MB OK) CloseWindow(0); outputfile=fopen ("lenaiwt.bmp","wb"): if(!outputfile) MessageBox("Cannot open file lenawt.raw",GetApplication()->GetName()
else if((x-1)>=0 && Image[x-1][y]==0) {x=x-1;Agent[i][0]=x;} else if((y-1)>=0&&Image[x][y-1]==0){y=y-1;Agent[i][1]=y;} else if((y+1)<32&&Image[x][y+1]==0){y=y+1;Agent[i][1]=y;} else {isAgentAlive[i]=0; ActiveAgent-=1;} } else { //**judge direction**// if((x+1)<32&&Image[x+1][y]==0){x=x+1;Agent[i][0]=x;} else if((x-1)>=0 && Image[x-1][y]==0) {x=x-1;Agent[i][0]=x;} else if((y-1)>=0&&Image[x][y-1]==0){y=y-1;Agent[i][1]=y;} else if((y+1)<32&&Image[x][y+1]==0){y=y+1;Agent[i][1]=y;} else {isAgentAlive[i]=0; ActiveAgent-=1;} } SearchTime++; }//**end if isAgentAlive==1 }//**end for }//**end while sprintf(ss,"%d",SearchTime); MessageBox(ss,"Total Search times",MB_OK); } } void TBmpViewWindow::CmWavelet() { unsigned i,j,k;int xs,ys; unsigned char buf[SIZE+1],buf1[1078]; FILE *inputfile,*mfile,*outputfile; inputfile=fopen("lena.bmp","rb"); if(!inputfile) { MessageBox("Cannot open file lena.raw", GetApplication()->GetName(), MB_OK); CloseWindow(0); } mfile=fopen("lenawt.bmp","wb"); if(!mfile) { MessageBox("Cannot open file lenawt.raw", GetApplication()->GetName(), MB_OK); CloseWindow(0); } outputfile=fopen("lenaiwt.bmp","wb"); if(!outputfile) { MessageBox("Cannot open file lenawt.raw", GetApplication()->GetName()
MB OK): CloseWindow(0) for(i=0:i<=SIZE-1:i++) if((imgx[i]=(float far*)farmalloc(SIZE*sizeof(float)))==NULL) Mes ageBox("Cannot malloc memory for displaying bitmap file" GetApplicationO->GetName.MB_OK): if((imgy [i]=(float far*)farmalloc(SIZE*sizeof(float)))==NULL) MessageBox("Cannot malloc memory for displaying bitmap file" GetApplication ->GetNa e(.MB_OK) if((img[i]=(float far*)farmalloc(SIZE*sizeof(float)))==NULL) MessageBox("Cannot malloc memory for displaying bitmap file", GetApplication(->GetName,MB_OK): CloseWindow(0) //read input file fread(buf1,1,1078,inputfile) for(1=0:1SZE:1++) fread(buf,1,SIZE,inputfile) for(j-0:j<SIZE:j++ img[i][6]=(f1oat)(uf[)-128.0: fclose(inputfile) //start wt. coef() xs=SI7E ys-SIZE: wt(xs.ys.SIZE,SIZE) xs=xs/2:ys=ys/2 wt (xs,ys,SIZE,SIZE): xs=xs/2:ys=ys/2: wt(xs,ys,SIZE,SIZE):
MB_OK); CloseWindow(0); } for(i=0;i<=SIZE-1;i++) { if((imgx[i]=(float far*)farmalloc(SIZE*sizeof(float)))==NULL) { MessageBox("Cannot malloc memory for displaying bitmap file", GetApplication()->GetName(), MB_OK); CloseWindow(0); } if((imgy[i]=(float far*)farmalloc(SIZE*sizeof(float)))==NULL) { MessageBox("Cannot malloc memory for displaying bitmap file", GetApplication()->GetName(), MB_OK); CloseWindow(0); } if((img[i]=(float far*)farmalloc(SIZE*sizeof(float)))==NULL) { MessageBox("Cannot malloc memory for displaying bitmap file", GetApplication()->GetName(), MB_OK); CloseWindow(0); } } //read input file fread(buf1,1,1078,inputfile); for(i=0;i<SIZE;i++) { fread(buf,1,SIZE,inputfile); for(j=0;j<SIZE;j++) img[i][j]=(float)(buf[j])-128.0; } fclose(inputfile); //start wt. coef(); xs=SIZE; ys=SIZE; wt(xs,ys,SIZE,SIZE); xs=xs/2;ys=ys/2; wt(xs,ys,SIZE,SIZE); xs=xs/2;ys=ys/2; wt(xs,ys,SIZE,SIZE);
/华**write the wt result files***/ fwrite(b f1, ,1078,file) for(i=0:i<SIZE;i++) for(j=0:j<SIZE:j++) buf[j]=(unsigned char)(s(img[i][j])+128) img[i][j]=(float)buf[j]-128.0: fwrite(buf,1,SIZE,mfile) fclose(mfile) //start inverse wt. iwt (xs.ys.SIZE.SIZE): Xg=2*s·Vg=2*vs· iwt(xs,ys,SIZE,SIZE): =2*x5:y iwt(xs,ys,SIZE,SIZE) fwrite(buf1.1,1078,outputfile) for(i=0:i<SIZE:i++) for(j=0:j<SIZE:j++) buf[]=(unsigned char)(s(img[i]])+128): fwrite(buf.1.SIZE,outputfile): fclose(outputfile): LoadBitmapFile("lenawt.bmp"); SetCaption(strlwr("lenawt.bmp")): LoadBitmapFile("lenaiwt.bmp"): SetCaption(strlwr("lenaiwt.bmp")); for(i=0:i<=SIZE-1:i++) farfree(imgy[i]) farfree(imgx[i]) farfree(img[i]): if(wavelet_direction==1)wavelet_direction=0; else wavelet direction=1;
//*****write the wt result file*****// fwrite(buf1,1,1078,mfile); for(i=0;i<SIZE;i++) { for(j=0;j<SIZE;j++) { buf[j]=(unsigned char)(s(img[i][j])+128); img[i][j]=(float)buf[j]-128.0; } fwrite(buf,1,SIZE,mfile); } fclose(mfile); //****start inverse wt.***// iwt(xs,ys,SIZE,SIZE); xs=2*xs;ys=2*ys; iwt(xs,ys,SIZE,SIZE); xs=2*xs;ys=2*ys; iwt(xs,ys,SIZE,SIZE); fwrite(buf1,1,1078,outputfile); for(i=0;i<SIZE;i++) { for(j=0;j<SIZE;j++) { buf[j]=(unsigned char)(s(img[i][j])+128); } fwrite(buf,1,SIZE,outputfile); } fclose(outputfile); /* LoadBitmapFile("lenawt.bmp"); SetCaption(strlwr("lenawt.bmp")); LoadBitmapFile("lenaiwt.bmp"); SetCaption(strlwr("lenaiwt.bmp")); */ for(i=0;i<=SIZE-1;i++) { farfree(imgy[i]); farfree(imgx[i]); farfree(img[i]); } if(wavelet_direction==1)wavelet_direction=0; else wavelet_direction=1; }
//Edge Process// inta(intx,int xsize) if(x<0)x=-x: if(x>=xsize)x=xsize*2-x-2; return(x): //Threshold// int s(float x) if(x>127)return(127): if(x<-l28)return(-128) return(x): //Set Inverse Filter Coefficients// void coef() int i; for(i=0:i<DD:i++) hi[i]=h[DD-1-i]: i]]: //********二维小波分解************************// void wt(int xs,int ys,long xsize,long ysize) int i,j,k.n; float templ,temp2: float bufferx[SIZE],buffery[SIZE]: for(n=0:n<ys:n++) for(i=0:i<xs:i+=2) temnl=0. emn2=0: for(Gj=-(DD-10/2:j=DD-1)/2:j+) templ=temp1+h[j+(DD-1)/2]*img[n][a(i+j,xs) for(=-(DD1)/2+1:j=(DD-1)/2+1:j+) temp2=temp2+g[j+(DD-1)/2-1]*img[n][a(i+j,xs)]: bufferx[i/2]=templ:
//Edge Process// int a(int x,int xsize) { if(x<0)x=-x; if(x>=xsize)x=xsize*2-x-2; return(x); } //Threshold// int s(float x) { if(x>127)return(127); if(x<-128)return(-128); return(x); } //Set Inverse Filter Coefficients// void coef() { int i; for(i=0;i<DD;i++) { hi[i]=h[DD-1-i]; gi[i]=g[DD-1-i]; } } //********二维小波分解************************// void wt(int xs,int ys,long xsize,long ysize) { int i,j,k,n; float temp1,temp2; float bufferx[SIZE],buffery[SIZE]; for(n=0;n<ys;n++) { for(i=0;i<xs;i+=2) { temp1=0; temp2=0; for(j=-(DD-1)/2;j<=(DD-1)/2;j++) temp1=temp1+h[j+(DD-1)/2]*img[n][a(i+j,xs)]; for(j=-(DD-1)/2+1;j<=(DD-1)/2+1;j++) temp2=temp2+g[j+(DD-1)/2-1]*img[n][a(i+j,xs)]; bufferx[i/2]=temp1;