?? walsh.cpp
字號:
#define EXTRA_NAME "@walshtransform."
#include "loadbmp.h"
#define Point(x,y) lpPoints[(x)+(y)*nWidth]
void WALh(double *f, double *W, int power)
{
int count;
int i,j,k,bfsize,p;
double *X1,*X2,*X;
count=1<<power;
X1=(double *)malloc(sizeof(double)*count);
X2=(double *)malloc(sizeof(double)*count);
memcpy(X1,f,sizeof(double)*count);
for(k=0;k<power;k++)
{
for(j=0;j<1<<k;j++)
{
bfsize=1<<(power-k);
for(i=0;i<bfsize/2;i++)
{
p=j*bfsize;
X2[i+p]=X1[i+p]+X1[i+p+bfsize/2];
X2[i+p+bfsize/2]=X1[i+p]-X1[i+p+bfsize/2];
}
}
X=X1;
X1=X2;
X2=X;
}
for(j=0;j<count;j++)
{
p=0;
for(i=0;i<power;i++)
{
if (j&(1<<i)) p+=1<<(power-i-1);
}
W[j]=X1[p]/count;
}
free(X1);
free(X2);
}
void Walsh()
{
int w=1,h=1,wp=0,hp=0;
while(w*2<=nWidth)
{
w*=2;
wp++;
}
while(h*2<=nHeight)
{
h*=2;
hp++;
}
int x,y;
BYTE *lpPoints=new BYTE[nWidth*nHeight];
GetPoints(lpPoints);
double *f=new double[w*h];
double *W=new double[w*h];
for(y=0;y<h;y++)
{
for(x=0;x<w;x++)
{
f[x+y*w]=Point(x,y);
}
}
for(y=0;y<h;y++)
{
WALh(f+w*y,W+w*y,wp);
}
for(y=0;y<h;y++)
{
for(x=0;x<w;x++)
{
f[x*h+y]=W[x+w*y];
}
}
for(x=0;x<w;x++)
{
WALh(f+x*h,W+x*h,hp);
}
double a;
memset(lpPoints,0,nWidth*nHeight);
for(y=0;y<h;y++)
{
for(x=0;x<w;x++)
{
a=fabs(W[x*h+y]*1000);
if (a>255) a=255;
Point(x,nHeight-y-1)=(BYTE)a;
}
}
delete f;
delete W;
PutPoints(lpPoints);
delete lpPoints;
}
void main(int argc, char *argv[])
{
if(argc==2)
FileName=argv[1];
else
return;
OpenFile();
Walsh();
SaveAs();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -