void CDemo1View::Onbin()
{ CDemo1Doc *pDoc=GetDocument(); ImageDib *pDib=pDoc->GetPDib(); //异常判断 if(pDib->m_nBitCount!=24&&pDib->m_nBitCount!=8){ ::MessageBox(0,"只处理彩色和灰度图像",MB_OK,0); return ; } //将pDib中的图像数据作为输入数据,调用带参数的构造函数, //定义GrayTrans类的对象graytrans int thd=250; GrayTrans graytrans(pDib->GetDimensions(),pDib->m_nBitCount, pDib->m_lpColorTable, pDib->m_pImgData); //调用Binary()对图像进行二值化,缺省状态下阈值为 graytrans.BinaryImage(thd); //建立一个新视图,显示分割结果 CMainFrame* pFrame = (CMainFrame *)(AfxGetApp()->m_pMainWnd); pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW); CDemo1View* pView=(CDemo1View*)pFrame->MDIGetActive()->GetActiveView(); CDemo1Doc* pDocNew=pView->GetDocument(); ImageDib *dibNew=pDocNew->GetPDib(); dibNew->ReplaceDib(graytrans.GetDimensions(),graytrans.m_nBitCountOut,graytrans.m_lpColorTableOut, graytrans.m_pImgDataOut); pView->OnInitialUpdate(); pDocNew->SetModifiedFlag(TRUE); pDocNew->UpdateAllViews(pView); }
二值化
void CDemo1View::Oncolreverse() { //获取文档类指针 CDemo1Doc *pDoc=GetDocument(); //获取ImgCenterDib类对象的指针,访问当前DIB数据 ImageDib *pDib=pDoc->GetPDib(); //DIB类型判断 if(pDib->m_nBitCount!=8){ ::MessageBox(0,"只处理灰度图像",MB_OK,0); return ; } //将pDib中的图像数据作为输入数据,调用带参数的构造函数, //定义GrayTrans类的对象graytrans GrayTrans graytrans(pDib->GetDimensions(), pDib->m_nBitCount,pDib->m_lpColorTable,pDib->m_pImgData); //调用ReverseImg()对图像求反 graytrans.RevImage(); //建立一个新视图,显示分割结果 CMainFrame* pFrame = (CMainFrame *)(AfxGetApp()->m_pMainWnd); //发送新建文件的消息,创建一个新的文档-视图 pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW); //获取新建视图指针 CDemo1View* pView=(CDemo1View*)pFrame->MDIGetActive()->GetActiveView(); //获取相关联的新的文档类指针 CDemo1Doc* pDocNew=pView->GetDocument(); //获取新文档中的ImgCenterDib类对象指针 ImageDib *dibNew=pDocNew->GetPDib(); //将变换后的输出图像作为新建文档的DIB进行显示 dibNew->ReplaceDib(graytrans.GetDimensions(),graytrans.m_nBitCountOut,graytrans.m_lpColorTableOut, graytrans.m_pImgDataOut); //设置滚动窗口 pView->OnInitialUpdate(); //文档数据置脏,提示存盘信息 pDocNew->SetModifiedFlag(TRUE); //各视图刷新显示 pDocNew->UpdateAllViews(pView); }
反色处理
void CDemo1View::OnFeatureDetect() { //获取文档类指针 CDemo1Doc *pDoc=GetDocument(); //获取ImgCenterDib类对象的指针,访问当前DIB数据 ImageDib *pDib=pDoc->GetPDib(); //DIB类型判断 if(pDib->m_nBitCount!=8){ ::MessageBox(0,"只处理灰度图像",MB_OK,0); return ; } GetFeature numDetect(pDib->GetDimensions(), pDib->m_nBitCount,pDib->m_lpColorTable,pDib->m_pImgData); numDetect.GetPosition(); numDetect.SetFeature(); numDetect.ShowFeature(); //建立一个新视图,显示分割结果 CMainFrame* pFrame = (CMainFrame *)(AfxGetApp()->m_pMainWnd); //发送新建文件的消息,创建一个新的文档-视图 pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW); //获取新建视图指针 CDemo1View* pView=(CDemo1View*)pFrame->MDIGetActive()->GetActiveView(); //获取相关联的新的文档类指针 CDemo1Doc* pDocNew=pView->GetDocument(); //获取新文档中的ImgCenterDib类对象指针 ImageDib *dibNew=pDocNew->GetPDib(); //将变换后的输出图像作为新建文档的DIB进行显示 dibNew->ReplaceDib(CSize(numDetect.m_imgWidthOut,numDetect.m_imgHeightOut),numDetect.m_nBitCountOut,numDetect.m_lpColorTableOut,numDetect.m_pImgDataOut); pView->OnInitialUpdate(); //文档数据置脏,提示存盘信息 pDocNew->SetModifiedFlag(TRUE); //各视图刷新显示 pDocNew->UpdateAllViews(pView); }
特征提取
void CDemo1View::Onrecognition() { NumRecognition numberRecog; number_no number; number=numberRecog.LeastDistance(); CString str; str.Format("应用最小距离法,\n自动分类识别结果为:%d",number.number); AfxMessageBox(str,MB_OK,NULL); //获取文档类指针 CDemo1Doc *pDoc=GetDocument(); //获取ImgCenterDib类对象的指针,访问当前DIB数据 ImageDib *pDib=pDoc->GetPDib(); //DIB类型判断 if(pDib->m_nBitCount!=8){ ::MessageBox(0,"只处理灰度图像",MB_OK,0); return ; } GetFeature numDetect(pDib->GetDimensions(), pDib->m_nBitCount,pDib->m_lpColorTable,pDib->m_pImgData); numDetect.ShowPattern(pattern[number.number].feature[number.no]); //建立一个新视图,显示分割结果 CMainFrame* pFrame = (CMainFrame *)(AfxGetApp()->m_pMainWnd); //发送新建文件的消息,创建一个新的文档-视图 pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW); //获取新建视图指针 CDemo1View* pView=(CDemo1View*)pFrame->MDIGetActive()->GetActiveView(); //获取相关联的新的文档类指针 CDemo1Doc* pDocNew=pView->GetDocument(); //获取新文档中的ImgCenterDib类对象指针 ImageDib *dibNew=pDocNew->GetPDib(); //将变换后的输出图像作为新建文档的DIB进行显示 dibNew->ReplaceDib(CSize(numDetect.m_imgWidthOut,numDetect.m_imgHeightOut),numDetect.m_nBitCountOut,numDetect.m_lpColorTableOut,numDetect.m_pImgDataOut); pView->OnInitialUpdate(); //文档数据置脏,提示存盘信息 pDocNew->SetModifiedFlag(TRUE); //各视图刷新显示 pDocNew->UpdateAllViews(pView); }
数字识别