cfarWord格式.docx
《cfarWord格式.docx》由会员分享,可在线阅读,更多相关《cfarWord格式.docx(14页珍藏版)》请在冰点文库上搜索。
//doublem_Threshold;
char*m_buffer;
//DialogData
//{{AFX_DATA(CCFARdialog)
enum{IDD=IDD_DIALOG2};
doublem_pf;
intm_method;
BOOLm_simple;
//}}AFX_DATA
//Overrides
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CCFARdialog)
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);
//DDX/DDVsupport
//}}AFX_VIRTUAL
//Implementation
protected:
//Generatedmessagemapfunctions
//{{AFX_MSG(CCFARdialog)
virtualvoidOnOK();
virtualBOOLOnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.
#endif//!
//CFARdialog.cpp:
implementationfile
#include"
stdafx.h"
DIBDisplay.h"
CFARdialog.h"
#include<
math.h>
Histogram.h"
stdio.h>
float.h>
iostream>
DibImage.h"
usingnamespacestd;
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
#definePI3.1415926
CCFARdialog:
:
CCFARdialog(CWnd*pParent/*=NULL*/)
:
CDialog(CCFARdialog:
IDD,pParent)
//{{AFX_DATA_INIT(CCFARdialog)
m_pf=0.0;
m_method=0;
m_simple=FALSE;
//}}AFX_DATA_INIT
}
voidCCFARdialog:
DoDataExchange(CDataExchange*pDX)
CDialog:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCFARdialog)
DDX_Text(pDX,IDC_EDIT1,m_pf);
DDX_Text(pDX,IDC_EDIT3,m_method);
DDX_Text(pDX,IDC_EDIT2,m_simple);
//}}AFX_DATA_MAP
BEGIN_MESSAGE_MAP(CCFARdialog,CDialog)
//{{AFX_MSG_MAP(CCFARdialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//CCFARdialogmessagehandlers
OnOK()
//TODO:
Addextravalidationhere
UpdateData(TRUE);
//Guassthresholdprecalculate
doublet[100][100];
doubletemp;
intk,i,m;
doublen;
doubleh,g,p;
doublemodified=1.0;
doublea=5.0;
doubleb=100.0;
doublee1=1e-8;
doublee2=1e-5;
LONGlLineBytes;
//图像每行的字节数
lLineBytes=WIDTHBYTES(m_lWidth*8);
do
{
h=(double)(b-a)/2;
t[0][0]=h*(exp(-a*a/2.0)/sqrt(2*PI)+exp(-b*b/2.0)/sqrt(2*PI));
k=1;
n=1;
do//Romberg算法
{
g=0;
for(i=1;
i<
=int(n);
i++)
temp=(a+((2*i-1)*h));
g=g+1/sqrt(2*PI)*exp(-temp*temp/2);
t[k][0]=(t[k-1][0]/2)+(h*g);
}
for(m=1;
m<
=k;
m++)
p=pow(4,(double)(m));
t[k-m][m]=(p*t[k-m+1][m-1]-t[k-m][m-1])/(p-1);
m-=1;
h/=2;
n*=2;
k+=1;
}while(fabs(t[0][m]-t[0][m-1])>
e1);
//自定义误差限e
if(t[0][m]<
m_pf)
a-=modified;
elseif(t[0][m]>
modified/=2;
a+=modified;
else
break;
}while(fabs(t[0][m]-m_pf)>
e2);
m_GaussNormThreshold=a;
m_buffer=newchar[lLineBytes*m_lHeight];
//m_lwidth*m_lHeight
if(m_simple==1)
Simplify();
elseif(m_simple==0)
if(m_method==1)
DoDetectCA();
elseif(m_method==2)
DoDetectOS();
AfxMessageBox("
Inputerror"
);
}
else
window=NULL;
m_buffer=NULL;
OnOK();
DoDetectCA()
inti,j;
intk=0;
intm=0;
doubletemp=0.0;
doublemu=0.0;
doublesigma=0.0;
unsignedchar*lpmodified;
unsignedchar*lpsave;
//Normal
for(i=0;
m_lHeight;
for(j=0;
j<
m_lWidth;
j++)
lpmodified=(unsignedchar*)m_lpDIBBits+lLineBytes*i+j;
lpsave=(unsignedchar*)m_buffer+lLineBytes*i+j;
m=Pit(i,j);
mu=0.0;
sigma=0.0;
while(k<
m)
{
mu+=window[k];
k++;
}
k=0;
mu/=m;
while(k<
m)
sigma+=pow((window[k]-mu),2);
sigma=sqrt(sigma/m);
if(m_GaussNormThreshold*sigma+mu<
(*lpmodified))
*lpsave=255;
else
*lpsave=0;
*lpmodified=*lpsave;
DoDetectOS()
{
m=Pit(i,j);
mu=window[(int)m/2-1];
sigma=window[(int)m/4*3-1]-window[(int)m/4-1];
BOOLCCFARdialog:
OnInitDialog()
OnInitDialog();
inti;
window=newunsignedchar[488];
//63*63-59*59backgroudwindowstatisticals
488;
window[i]=0;
returnTRUE;
//returnTRUEunlessyousetthefocustoacontrol
//EXCEPTION:
OCXPropertyPagesshouldreturnFALSE
intCCFARdialog:
Pit(intm,intn)//矩捕,搞定空心正方形像素
unsignedchar*lpSrc;
intk=0,p=0,q=-1;
for(i=-31;
=31;
for(j=-31;
if((abs(i)>
=30||abs(j)>
=30)&
&
m_lHeight>
(m+i)&
(m+i)>
=0&
m_lWidth>
(n+j)&
(n+j)>
=0)//判断是否属于环心
lpSrc=(unsignedchar*)m_lpDIBBits+lLineBytes*(m+i)+(n+j);
if(m_method==1)//CA-CFARdirectlyevalue
{
window[k]=*(lpSrc);
k++;
}
else//OS-CFARordering
temp=*(lpSrc);
if(k==0)
{
window[0]=temp;
k++;
}
else
while(p<
k)
{
if(temp<
window[p])
{
q=p;
for(p=k;
p>
q;
p--)
window[p]=window[p-1];
window[q]=temp;
break;
}
else
p++;
}
if(q==-1)
window[k]=temp;
k++;
p=0;
q=-1;
returnk;
Simplify()
inti,j,m,n,p;
intlen=0;
for(i=1;
i=i+3)
for(j=1;
j=j+3)
lpSrc=(unsignedchar*)m_lpDIBBits+lLineBytes*i+j;
for(m=-1;
=1;
for(n=-1;
n<
n++)
if(*(lpSrc)<
=100&
m+i&
m+i>
n+j&
n+j>
=0)
lpSrc=(unsignedchar*)m_lpDIBBits+lLineBytes*(m+i)+(n+j);
lpsave=(unsignedchar*)m_buffer+lLineBytes*(m+i)+(n+j);
*lpsave=0;
elseif(m_lHeight>
=0)
lpSrc=(unsignedchar*)m_lpDIBBits+lLineBytes*(m+i)+(n+j);
len=Pit((m+i),(n+j));
if(m_method==1)
for(p=0;
p<
len;
p++)
mu+=window[p];
mu/=len;
sigma+=pow((window[p]-mu),2);
sigma=sqrt(sigma/len);
mu=window[(int)len/2-1];
sigma=window[(int)len/4*3-1]-window[(int)len/4-1];
if(m_GaussNormThreshold*sigma+mu<
(*lpSrc))
*lpsave=255;
else
*lpsave=0;
*lpSrc=*lpsave;