数学形态学处理程序实例Word文档格式.docx
《数学形态学处理程序实例Word文档格式.docx》由会员分享,可在线阅读,更多相关《数学形态学处理程序实例Word文档格式.docx(32页珍藏版)》请在冰豆网上搜索。
BEGIN_MESSAGE_MAP(CJEFFView,CScrollView)
//{{AFX_MSG_MAP(CJEFFView)
ON_COMMAND(ID_EROSION,OnErosion)
ON_COMMAND(ID_DILATION,OnDilation)
ON_COMMAND(ID_OPEN,OnOpen)
ON_COMMAND(ID_CLOSE,OnClose)
ON_COMMAND(ID_ZAOSHENG,OnZaosheng)
ON_COMMAND(ID_BIANYUAN,OnBianyuan)
ON_COMMAND(ID_1,On1)
ON_COMMAND(ID_2,On2)
ON_COMMAND(ID_4,On4)
ON_COMMAND(ID_8,On8)
ON_COMMAND(ID_DILATION2,OnDilation2)
ON_COMMAND(ID_EROSION2,OnErosion2)
ON_COMMAND(ID_OPEN2,OnOpen2)
ON_COMMAND(ID_CLOSE2,OnClose2)
ON_COMMAND(ID_SMOOTH,OnSmooth)
ON_COMMAND(ID_RELOAD,OnReload)
ON_COMMAND(ID_TIDU,OnTidu)
ON_COMMAND(ID_BIANYUAN_H,OnBianyuanH)
ON_COMMAND(ID_QUSE,OnQuse)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
//Standardprintingcommands
ON_COMMAND(ID_FILE_PRINT,CScrollView:
:
OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT,CScrollView:
ON_COMMAND(ID_FILE_PRINT_PREVIEW,CScrollView:
OnFilePrintPreview)
END_MESSAGE_MAP()
//CJEFFViewconstruction/destruction
CJEFFView:
CJEFFView()
{
//TODO:
addconstructioncodehere
ValidDoc=FALSE;
m_i=1;
}
~CJEFFView()
BOOLCJEFFView:
PreCreateWindow(CREATESTRUCT&
cs)
ModifytheWindowclassorstylesherebymodifying
//theCREATESTRUCTcs
returnCScrollView:
PreCreateWindow(cs);
//CJEFFViewdrawing
voidCJEFFView:
OnDraw(CDC*pDC)
CJEFFDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
adddrawcodefornativedatahere
if(pDoc->
lpBitmap)
{
ValidDoc=TRUE;
nWidth=pDoc->
nWidth;
nHeight=pDoc->
nHeight;
lpBits=pDoc->
lpBits;
lpPoints=pDoc->
lpPoints;
BITMAPINFOHEADERbmi;
bmi.biSize=sizeof(BITMAPINFOHEADER);
bmi.biWidth=nWidth;
bmi.biHeight=nHeight;
bmi.biPlanes=1;
bmi.biBitCount=24;
bmi.biCompression=BI_RGB;
bmi.biSizeImage=0;
bmi.biXPelsPerMeter=0;
bmi.biYPelsPerMeter=0;
bmi.biClrUsed=0;
bmi.biClrImportant=0;
StretchDIBits(pDC->
m_hDC,0,0,nWidth*m_i,nHeight*m_i,0,0,nWidth,nHeight,
lpBits,
(BITMAPINFO*)&
bmi,
DIB_RGB_COLORS,
SRCCOPY);
}
OnInitialUpdate()
CScrollView:
OnInitialUpdate();
CSizesizeTotal;
calculatethetotalsizeofthisview
sizeTotal.cx=2000;
sizeTotal.cy=1700;
SetScrollSizes(MM_TEXT,sizeTotal);
//CJEFFViewprinting
OnPreparePrinting(CPrintInfo*pInfo)
//defaultpreparation
returnDoPreparePrinting(pInfo);
OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
addextrainitializationbeforeprinting
OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
addcleanupafterprinting
//CJEFFViewdiagnostics
AssertValid()const
AssertValid();
Dump(CDumpContext&
dc)const
Dump(dc);
CJEFFDoc*CJEFFView:
GetDocument()//non-debugversionisinline
ASSERT(m_pDocument->
IsKindOf(RUNTIME_CLASS(CJEFFDoc)));
return(CJEFFDoc*)m_pDocument;
#endif//_DEBUG
//CJEFFViewmessagehandlers
//二值形态学:
腐蚀
OnErosion()
int*lpMarks=newint[nWidth*nHeight];
intx,y,x1,y1;
intcount;
//中间变量
for(y=1;
y<
nHeight-1;
y++)
for(x=1;
x<
nWidth-1;
x++)
{
count=1;
for(y1=-1;
y1<
2;
y1++)
{
for(x1=-1;
x1<
x1++)
{
if(Out(x+x1,y+y1))//以(x,y)为中心的九个点是否有白色的像素点
count=0;
//如果有count=0,否则count=1;
}
}
if(count)lpMarks[x+y*nWidth]=1;
//黑色像素点记为1
elselpMarks[x+y*nWidth]=0;
//白色像素点记为0
}
if(lpMarks[x+y*nWidth]==0)Out(x,y)=255;
//白色像素点灰度为255
deletelpMarks;
//释放内存
GetDocument()->
PutPoint();
Invalidate();
膨胀
OnDilation()
count=0;
if(Out(x+x1,y+y1)==0)//以(x,y)为中心的九个点是否有黑色的像素点
count=1;
//若有记为一