cfar.docx
- 文档编号:7205126
- 上传时间:2023-05-11
- 格式:DOCX
- 页数:14
- 大小:17.27KB
cfar.docx
《cfar.docx》由会员分享,可在线阅读,更多相关《cfar.docx(14页珍藏版)》请在冰点文库上搜索。
cfar
#if!
defined(AFX_CFARDIALOG_H__20C22654_7204_4829_9DE3_9349AEB78DAA__INCLUDED_)
#defineAFX_CFARDIALOG_H__20C22654_7204_4829_9DE3_9349AEB78DAA__INCLUDED_
#if_MSC_VER>1000
#pragmaonce
#endif//_MSC_VER>1000
//CFARdialog.h:
headerfile
//
/////////////////////////////////////////////////////////////////////////////
//CCFARdialogdialog
classCCFARdialog:
publicCDialog
{
//Construction
public:
CCFARdialog(CWnd*pParent=NULL);//standardconstructor
voidDoDetectCA();//executedetectionCA-CFAR
voidDoDetectOS();//executedetectionOS-CFAR
intPit(intm,intn);//executemodelpatch
voidSimplify();//simplifiedprocess
char*m_lpDIBBits;
LONGm_lHeight;
LONGm_lWidth;
//doubledoingmodel[256];
unsignedchar*window;
doublem_GaussNormThreshold;
//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//!
defined(AFX_CFARDIALOG_H__20C22654_7204_4829_9DE3_9349AEB78DAA__INCLUDED_)
//CFARdialog.cpp:
implementationfile
//
#include"stdafx.h"
#include"DIBDisplay.h"
#include"CFARdialog.h"
#include
#include"Histogram.h"
#include
#include
#include
#include"DibImage.h"
usingnamespacestd;
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
#definePI3.1415926
/////////////////////////////////////////////////////////////////////////////
//CCFARdialogdialog
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
voidCCFARdialog:
:
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] { a-=modified; } elseif(t[0][m]>m_pf) { 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(); else AfxMessageBox("Inputerror"); } else AfxMessageBox("Inputerror"); window=NULL; m_buffer=NULL; CDialog: : OnOK(); } voidCCFARdialog: : DoDetectCA() { inti,j; intk=0; intm=0; doubletemp=0.0; doublemu=0.0; doublesigma=0.0; unsignedchar*lpmodified; unsignedchar*lpsave; LONGlLineBytes;//图像每行的字节数 lLineBytes=WIDTHBYTES(m_lWidth*8); //Normal for(i=0;i { for(j=0;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 { mu+=window[k]; k++; } k=0; mu/=m; while(k { sigma+=pow((window[k]-mu),2); k++; } k=0; sigma=sqrt(sigma/m); if(m_GaussNormThreshold*sigma+mu<(*lpmodified)) *lpsave=255; else *lpsave=0; } } for(i=0;i { for(j=0;j { lpmodified=(unsignedchar*)m_lpDIBBits+lLineBytes*i+j; lpsave=(unsignedchar*)m_buffer+lLineBytes*i+j; *lpmodified=*lpsave; } } } voidCCFARdialog: : DoDetectOS() { inti,j; intk=0; intm=0; doubletemp=0.0; doublemu=0.0; doublesigma=0.0; unsignedchar*lpmodified; unsignedchar*lpsave; LONGlLineBytes;//图像每行的字节数 lLineBytes=WIDTHBYTES(m_lWidth*8); for(i=0;i { for(j=0;j { lpmodified=(unsignedchar*)m_lpDIBBits+lLineBytes*i+j; lpsave=(unsignedchar*)m_buffer+lLineBytes*i+j; mu=0.0; sigma=0.0; m=Pit(i,j); mu=window[(int)m/2-1]; sigma=window[(int)m/4*3-1]-window[(int)m/4-1]; if(m_GaussNormThreshold*sigma+mu<(*lpmodified)) *lpsave=255; else *lpsave=0; } } for(i=0;i { for(j=0;j { lpmodified=(unsignedchar*)m_lpDIBBits+lLineBytes*i+j; lpsave=(unsignedchar*)m_buffer+lLineBytes*i+j; *lpmodified=*lpsave; } } } BOOLCCFARdialog: : OnInitDialog() { CDialog: : OnInitDialog(); inti; window=newunsignedchar[488];//63*63-59*59backgroudwindowstatisticals for(i=0;i<488;i++) { window[i]=0; } returnTRUE;//returnTRUEunlessyousetthefocustoacontrol //EXCEPTION: OCXPropertyPagesshouldreturnFALSE } intCCFARdialog: : Pit(intm,intn)//矩捕,搞定空心正方形像素 { inti,j; unsignedchar*lpSrc; intk=0,p=0,q=-1; doubletemp=0.0; LONGlLineBytes;//图像每行的字节数 lLineBytes=WIDTHBYTES(m_lWidth*8); for(i=-31;i<=31;i++) { for(j=-31;j<=31;j++) { 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 { if(temp { 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; } voidCCFARdialog: : Simplify() { unsignedchar*lpsave; unsignedchar*lpSrc; inti,j,m,n,p; intlen=0; doublemu=0.0; doublesigma=0.0; LONGlLineBytes;//图像每行的字节数 lLineBytes=WIDTHBYTES(m_lWidth*8); for(i=1;i { for(j=1;j { lpSrc=(unsignedchar*)m_lpDIBBits+lLineBytes*i+j; for(m=-1;m<=1;m++) for(n=-1;n<=1;n++) { if(*(lpSrc)<=100&&m_lHeight>m+i&&m+i>=0&&m_lWidth>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>m+i&&m+i>=0&&m_lWidth>n+j&&n+j>=0) { lpSrc=(unsignedchar*)m_lpDIBBits+lLineBytes*(m+i)+(n+j); lpsave=(unsignedchar*)m_buffer+lLineBytes*(m+i)+(n+j); len=Pit((m+i),(n+j)); if(m_method==1) { for(p=0;p mu+=window[p]; mu/=len; for(p=0;p sigma+=pow((window[p]-mu),2); sigma=sqrt(sigma/len); } else { 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; } } } } for(i=0;i { for(j=0;j { lpSrc=(unsignedchar*)m_lpDIBBits+lLineBytes*i+j; lpsave=(unsignedchar*)m_buffer+lLineBytes*i+j; *lpSrc=*lpsave; } } }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- cfar