📄 fpdirectionimage.cpp
字号:
lpDirectionImage[x][y]=2;
else if(AngleAvg >= 11.25)
lpDirectionImage[x][y]=1;
else
lpDirectionImage[x][y]=0;
}
}
else
lpDirectionImage[x][y]=8;
Weight[x][y].weight0=(float)weight0;
Weight[x][y].weight1=(float)weight1;
Weight[x][y].weight2=(float)weight2;
}
for(i=0;i<IMAGE_SIZE-START_POINT*2 +12; i++)
{
GlobalUnlock(hW0[i]);
GlobalFree(hW0[i]);
GlobalUnlock(hW1[i]);
GlobalFree(hW1[i]);
GlobalUnlock(hW2[i]);
GlobalFree(hW2[i]);
}
}
//Function: create blockwise16*16 direction image,
// include discrete and continuous value
//Method: Weight[][] -> AngleAvg -> DirectionBlock[][]
//Input parameter: Weight[][DIR_IMAGE_SIZE]
//Output parameter: DirectionBlock[][BLOCK_NO]
void CreateDirectionBlockContinous(WEIGHT *Weight[DIR_IMAGE_SIZE],
PBYTE DirectionBlock[BLOCK_NO])
{
short x,y;
short bx,by;
double Weight0,Weight1,Weight2;
float AngleAvg;
for(bx=0;bx<BLOCK_NO;bx++) //#define BLOCK_NO 32 in preprocess.h
for(by=0;by<BLOCK_NO;by++)
{
Weight0=0;
Weight1=0;
Weight2=0;
for(x=bx*BLOCK_SIZE;x<(bx+1)*BLOCK_SIZE;x++) //#define BLOCK_SIZE 16 in preprocess.h
for(y=by*BLOCK_SIZE;y<(by+1)*BLOCK_SIZE;y++)
{
Weight0+=Weight[x][y].weight0;
Weight1+=Weight[x][y].weight1;
Weight2+=Weight[x][y].weight2;
}
AngleAvg=CaculateAngle(Weight0,Weight1,Weight2);
if( AngleAvg >= 78.75)
{
if(AngleAvg < 101.25)
DirectionBlock[bx][by]=4;
else if(AngleAvg <= 123.75)
DirectionBlock[bx][by]=5;
else if(AngleAvg <= 146.25)
DirectionBlock[bx][by]=6;
else if(AngleAvg <= 168.75)
DirectionBlock[bx][by]=7;
else if(AngleAvg<=180)
DirectionBlock[bx][by]=0;
else
DirectionBlock[bx][by]=8;
}
else
{
if(AngleAvg >= 56.25)
DirectionBlock[bx][by]=3;
else if(AngleAvg >= 33.75)
DirectionBlock[bx][by]=2;
else if(AngleAvg >= 11.25)
DirectionBlock[bx][by]=1;
else
DirectionBlock[bx][by]=0;
}
}
}
//Function: create blockwise8*8 direction image,
// include discrete and continuous value
//Method: Weight[][] -> AngleAvg -> DirectionBlock[][]
//Input parameter: Weight[][DIR_IMAGE_SIZE]
//Output parameter: DirectionBlock[][BLOCK_NO]
void CreateDirectionBlockContinous8(WEIGHT *Weight[DIR_IMAGE_SIZE],
PBYTE DirectionBlock[BLOCK_NO*2])
{
short x,y;
short bx,by;
double Weight0,Weight1,Weight2;
float AngleAvg;
for(bx=0;bx<BLOCK_NO*2;bx++) //#define BLOCK_NO 32 in preprocess.h
for(by=0;by<BLOCK_NO*2;by++)
{
Weight0=0;
Weight1=0;
Weight2=0;
for(x=bx*BLOCK_SIZE/2;x<(bx+1)*BLOCK_SIZE/2;x++) //#define BLOCK_SIZE 16 in preprocess.h
for(y=by*BLOCK_SIZE/2;y<(by+1)*BLOCK_SIZE/2;y++)
{
Weight0+=Weight[x][y].weight0;
Weight1+=Weight[x][y].weight1;
Weight2+=Weight[x][y].weight2;
}
AngleAvg=CaculateAngle(Weight0,Weight1,Weight2);
if( AngleAvg >= 78.75)
{
if(AngleAvg < 101.25)
DirectionBlock[bx][by]=4;
else if(AngleAvg <= 123.75)
DirectionBlock[bx][by]=5;
else if(AngleAvg <= 146.25)
DirectionBlock[bx][by]=6;
else if(AngleAvg <= 168.75)
DirectionBlock[bx][by]=7;
else if(AngleAvg<=180)
DirectionBlock[bx][by]=0;
else
DirectionBlock[bx][by]=8;
}
else
{
if(AngleAvg >= 56.25)
DirectionBlock[bx][by]=3;
else if(AngleAvg >= 33.75)
DirectionBlock[bx][by]=2;
else if(AngleAvg >= 11.25)
DirectionBlock[bx][by]=1;
else
DirectionBlock[bx][by]=0;
}
}
}
//Function: to create discrete blockwise direction image
// through discrete pointwise direction image
//Method:
//Input: lpDirectionImage[][DIR_IMAGE_SIZE], BackBlock[][SEG_BLOCK_NO]
//Output: DirectionBlock[][BLOCK_NO]
//Other: DIR_IMAGE_SIZE :512 SEG_BLOCK_NO: 32 BLOCK_NO :32
void CreateDirectionBlock(PBYTE lpDirectionImage[DIR_IMAGE_SIZE],
PBOOL BackBlock[SEG_BLOCK_NO],
PBYTE DirectionBlock[BLOCK_NO])
{
short x,y;
short bx,by;
short i,j;
BYTE MaxDir;
BYTE k;
short Direction[9];
for(bx=0;bx<BLOCK_NO;bx++)
for(by=0;by<BLOCK_NO;by++)
{
if(BackBlock[bx][by]!=TRUE && BackBlock[bx][by]!=REJECT)// 不是本底,也不是不可信区
{
for(i=0;i<8;i++)
Direction[i]=0;
for(x=bx*BLOCK_SIZE,i=bx*BLOCK_SIZE+BLOCK_SIZE;x<i;x ++)
for(y=by*BLOCK_SIZE,j=by*BLOCK_SIZE+BLOCK_SIZE;y<j;y ++)
{
k=lpDirectionImage[x][y];
Direction[k]++; //按方向直方图统计的方法
}
MaxDir=0;
for(k=1;k<8;k++)
{
if(Direction[k]>Direction[MaxDir])
MaxDir=k;
}
DirectionBlock[bx][by]=MaxDir;
}
}
}
//Function: to create DirectionBlock with Lawrence method (continous).
//Input parameter: PBYTE pSrc[],
//Output parameter: WEIGHT *lpWeight[DIR_IMAGE_SIZE] , PBYTE DirectionBlock[]
void DirectionProcess(
PBYTE pSrc[IMAGE_SIZE], //[in]
WEIGHT *lpWeight[DIR_IMAGE_SIZE], //[out]
PBYTE DirectionBlock8[BLOCK_NO*2], //[out]
PBYTE lpDirectionImage[DIR_IMAGE_SIZE]) //[out]
{
int i,j;
BYTE *pSrcNTem[IMAGE_SIZE];
HANDLE hSrcNTem[IMAGE_SIZE]; //存放正常屏幕坐标下原图象坐标544*544
BYTE *pSrcTem[IMAGE_SIZE];
HANDLE hSrcTem[IMAGE_SIZE];
int AllocSize=IMAGE_SIZE*sizeof(BYTE);
for(i=0; i<IMAGE_SIZE; i++)
{
hSrcNTem[i]=(HGLOBAL)GlobalAlloc(GHND,AllocSize);
hSrcTem[i]=(HGLOBAL)GlobalAlloc(GHND,AllocSize);
if(!hSrcNTem[i]||!hSrcTem[i])
{
AfxMessageBox("not enough memory1 in DirectionProcess()!");
return ;
}
pSrcNTem[i] = (BYTE *)GlobalLock(hSrcNTem[i]); //存放正常屏幕坐标下原图象坐标
pSrcTem[i] = (BYTE *)GlobalLock(hSrcTem[i]);
if((pSrcNTem[i] == NULL)||(pSrcTem[i]==NULL))
{
AfxMessageBox("not enough memory!");
return ;
}
}
for(i=0;i<=IMAGE_SIZE-1;i++)
for(j=0;j<=IMAGE_SIZE-1;j++)
pSrcTem[i][j]=pSrc[543-i][j];
for(i=0;i<=IMAGE_SIZE-1;i++)
for(j=0;j<=IMAGE_SIZE-1;j++)
pSrcNTem[i][j]=pSrcTem[j][i];
CreateDirectionImageEasyLawrence2(pSrcNTem,lpWeight,lpDirectionImage);
CreateDirectionBlockContinous8(lpWeight, DirectionBlock8);
for(i=0;i<IMAGE_SIZE;i++)
{
GlobalUnlock(hSrcTem[i]);
GlobalFree(hSrcTem[i]);
GlobalUnlock(hSrcNTem[i]);
GlobalFree(hSrcNTem[i]);
}
}
//Function: Caclute continuous direction image blockwise through direction weight
// normal: return direction value less than 180; backgroud: return 360
// Formula:
// AngleAvg=(float)(AngleMax +or- 30*(WeightMid-WeightMin)/(WeightMax-WeightMin));
// input parameter: Weight0 (<--> Angle 90 ?)
// Weight1 (<--> Angle 150 ?)
// Weight2 (<--> Angle 30 ?)
// output parameter: AngleAvgfloat
float CaculateAngle(double Weight0, double Weight1, double Weight2)
{
double WeightMax,WeightMid,WeightMin;
float AngleAvg,AngleMax,AngleMid,AngleMin;
if(Weight0>Weight1)
{
if(Weight2>Weight0)
{
WeightMax=Weight2;
WeightMid=Weight0;
WeightMin=Weight1;
AngleMax=30;
AngleMid=90;
AngleMin=150;
}
else if(Weight2<Weight1)
{
WeightMax=Weight0;
WeightMid=Weight1;
WeightMin=Weight2;
AngleMax=90;
AngleMid=150;
AngleMin=30;
}
else
{
WeightMax=Weight0;
WeightMid=Weight2;
WeightMin=Weight1;
AngleMax=90;
AngleMid=30;
AngleMin=150;
}
}
else
{
if(Weight2<Weight0)
{
WeightMax=Weight1;
WeightMid=Weight0;
WeightMin=Weight2;
AngleMax=150;
AngleMid=90;
AngleMin=30;
}
else if(Weight2>Weight1)
{
WeightMax=Weight2;
WeightMid=Weight1;
WeightMin=Weight0;
AngleMax=30;
AngleMid=150;
AngleMin=90;
}
else
{
WeightMax=Weight1;
WeightMid=Weight2;
WeightMin=Weight0;
AngleMax=150;
AngleMid=30;
AngleMin=90;
}
}
if(fabs(WeightMax-WeightMin) > 1 )
{
if( (AngleMax-AngleMid == 60) || (AngleMax-AngleMid == -120) )
AngleAvg=(float)(AngleMax-30*(WeightMid-WeightMin)/(WeightMax-WeightMin));
else if( (AngleMax-AngleMid == -60) || (AngleMax-AngleMid == 120) )
AngleAvg=(float)(AngleMax+30*(WeightMid-WeightMin)/(WeightMax-WeightMin));
}
else
AngleAvg=360;
return AngleAvg;
}
//Function: to create DirectionBlock with Mehtre Method (discrete)
//Input parameter: pSrc[][], BackBlock[][]
//Output parameter: DirectionBlock[][], DWEIGHT *lpDWeight[DIR_IMAGE_SIZE]
void DirectionProcessForFiltSeg(PBYTE lpDirectionImage[DIR_IMAGE_SIZE],
PBOOL BackBlock[SEG_BLOCK_NO],
PBYTE pSrc[IMAGE_SIZE],
PBYTE DirectionBlock[BLOCK_NO],
DWEIGHT *lpDWeight[DIR_IMAGE_SIZE])
{
CreateDirectionImage17v2(pSrc, BackBlock, lpDirectionImage, lpDWeight);
CreateDirectionBlock(lpDirectionImage, BackBlock, DirectionBlock);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -