資源簡介
Gabor濾波器C++程序,因自己需要用,所以就寫了個。
在此給出了.cpp文件,而.h文件只需要根據程序名稱自動生成即可
希望大家能用的著:)
代碼片段和文件信息
#include?“StdAfx.h“
#include?“Gabor.h“
#include?
#include?
CGabor::CGabor(void)
{
}
CGabor::~CGabor(void)
{
}
#define SIZE_L 32
#define SIZE_W 16
#define SIZE_L2 16
#define SIZE_W2 8
#ifndef?PI
#define?PI?3.1415926535897932384626433832795
#endif
/*
?Function?Name :?Frequency
?Functionality :?Prepare?frequency?For?Gabor?Filter
??
*/
int?CGabor::Frequency(unsigned?char?*?ucImg?double?*?fDirection?double?*?fFrequency?long?lWidth?long?lHeight)
{
//?the?peak?point?of?the?sin?wave
int peak_pos[SIZE_L];
int peak_cnt;
double peak_freq;
double Xsig[SIZE_L];
// double pmin?=?0?pmax?=?0;
//?directions
????double dir?=?0.0;
????double cosdir?=?0.0;
????double sindir?=?0.0;
double maxPeak?minPeak;
double *frequency1?=?new?double[lWidth*lHeight];
memset(fFrequency?0?sizeof(double)*lWidth*lHeight);
memset(frequency1?0?sizeof(double)*lWidth*lHeight);
long xy;
long dk;
long uv;
for(y=SIZE_L2;?y {
for(x=SIZE_L2;?x {
dir =?fDirection[(y+SIZE_W2)*lWidth?+?(x+SIZE_W2)];
cosdir =?-sin(dir);
sindir =?cos(dir);
// calc?the?x-signature?X[0]...X[L-1]
for(k=0;?k {
Xsig[k]?=?0.0;
for(d=0;?d {
u?=?(long)(x?+?(d-SIZE_W2)*cosdir?+?(k-SIZE_L2)*sindir);
v?=?(long)(y?+?(d-SIZE_W2)*sindir?-?(k-SIZE_L2)*cosdir);
//?never?over?the?edge
if(u<0)
u?=0;
else?if(u>lWidth-1)
u?=?lWidth-1;
if(v<0)
v?=?0;
else?if(v>lHeight-1)
v?=?lHeight-1;
Xsig[k]?+=?ucImg[u+v*lWidth];
}
Xsig[k]?/=?SIZE_W;
}
//?here?we?have?got?the?SIN?wave
//?see?if?the?wave?exists?max?and?min?value?should?have?a?range
maxPeak?=?minPeak?=?Xsig[0];
for(k=0;?k {
if(minPeak>Xsig[k])
minPeak =?Xsig[k];
if(maxPeak maxPeak =?Xsig[k];
}
peak_cnt =?0;
if((maxPeak?-?minPeak)>64)
{
for(k=0;?k {
if((Xsig[k-1]?=?Xsig[k+1]))
peak_pos[peak_cnt++]?=?k;
}
}
//?mean?peak
peak_freq =?0.0;
if(peak_cnt>=2)
{
for(k=0;?k {
peak_freq +=?(peak_pos[k+1]?-?peak_pos[k]);
}
peak_freq /=?peak_cnt-1;
}
//?peak?frequency?should?be?limited
if(peak_freq<3.0?||?peak_freq>25.0)
frequency1[x+y*lWidth]?=?0.0;
else
frequency1[x+y*lWidth]?=?1.0/peak_freq;
}
}
//?mean?filter?for?the?frequency
for(y=SIZE_L2;?y {
for(x=SIZE_L2;?x {
k?=?x+y*lWidth;
peak_freq?=?0.0;
for(v=-2;?v<=2;?v++)
{
for(u=-2;?u<=2;?u++)
{
peak_freq +=?frequency1[(x+u)+(y+v)*lWidth];
}
}
fFrequency[k]?=?peak_freq/25;
}
}
delete?frequency1;
return?0;
}
/*
?Function?Name :?ImageEnhance
?Functionality :?image?enc
- 上一篇:GoBackN協議的C語言實現
- 下一篇:數據結構-報刊管理系統
評論
共有 條評論