📄 hongmoview.cpp
字号:
// hongmoView.cpp : implementation of the CHongmoView class
//
#include "stdafx.h"
#include "hongmo.h"
#include "hongmoDoc.h"
#include "hongmoView.h"
#include "GlobalApi.h"
#include "GUIYIHUA.h"
#include "Cdib.h"
#include "math.h"
#include <complex>
using namespace std;
#define pi 3.1415927
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHongmoView
IMPLEMENT_DYNCREATE(CHongmoView, CScrollView)
BEGIN_MESSAGE_MAP(CHongmoView, CScrollView)
//{{AFX_MSG_MAP(CHongmoView)
ON_COMMAND(ID_CAOZUO_CANNYDETECTION, OnCaozuoCannydetection)
ON_COMMAND(ID_CAOZUO_DINGWEI, OnCaozuoDingwei)
ON_COMMAND(ID_CAOZUO_GUIYIHUA, OnCaozuoGuiyihua)
ON_COMMAND(ID_CAOZUO_JUNHENG, OnCaozuoJunheng)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHongmoView construction/destruction
CHongmoView::CHongmoView()
{
// TODO: add construction code here
}
CHongmoView::~CHongmoView()
{
}
BOOL CHongmoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CHongmoView drawing
void CHongmoView::OnDraw(CDC* pDC)
{
CHongmoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CSize sizeDibDisplay;
if(!pDoc->m_pDibInit->IsEmpty())
{
sizeDibDisplay = pDoc->m_pDibInit->GetDimensions();
pDoc->m_pDibInit->Draw(pDC,CPoint(0,0),sizeDibDisplay);
}
}
/////////////////////////////////////////////////////////////////////////////
// CHongmoView printing
BOOL CHongmoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CHongmoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CHongmoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CHongmoView diagnostics
#ifdef _DEBUG
void CHongmoView::AssertValid() const
{
CScrollView::AssertValid();
}
void CHongmoView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CHongmoDoc* CHongmoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHongmoDoc)));
return (CHongmoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHongmoView message handlers
void CHongmoView::OnInitialUpdate()
{
// CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CScrollView::OnInitialUpdate();
CHongmoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CSize sizeTotal = pDoc->m_pDibInit->GetDimensions();
//已改动
SetScrollSizes(MM_TEXT, sizeTotal);
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
void CHongmoView::OnCaozuoCannydetection()
{
// TODO: Add your command handler code here
CHongmoDoc * pDoc = (CHongmoDoc *)this->GetDocument();
CDib * pDib = pDoc->m_pDibInit;
LPBITMAPINFOHEADER lpBMIH=pDib->m_lpBMIH;
// 判断是否是8-bpp位图
if (lpBMIH->biBitCount != 8)
{
// 提示用户
MessageBox("目前只支持256色位虹膜图像的边缘检测!", "系统提示" ,
MB_ICONINFORMATION | MB_OK);
// 返回
return;
}
//更改光标形状
BeginWaitCursor();
/*************************************************/
//循环变量
int i;
int j;
/*************************************************/
CSize sizeImage = pDib->GetDimensions();
int nWidth = sizeImage.cx;
int nHeight= sizeImage.cy;
int nSaveWidth = pDib->GetDibSaveDim().cx;
// 开辟内存,存储图象数据
unsigned char * pUnchImage = new unsigned char[nWidth*nHeight];
for(i=0; i<nHeight; i++)
{
for(j=0; j<nWidth; j++)
{
pUnchImage[i*nWidth+j] = pDib->m_lpImage[i*nSaveWidth+j];
}
}
// canny算子计算后的结果
unsigned char * pUnchEdge = new unsigned char[nWidth*nHeight];
// 导数x的方向指针
double * CosTheta = new double [nWidth*nHeight];
// 导数y的方向指针
double * SinTheta = new double [nWidth*nHeight];
/*************************************************/
// 调用Canny()函数对虹膜图像进行边缘检测
Canny(pUnchImage, nWidth, nHeight, 0.8, 0.44, 0.83, pUnchEdge,CosTheta,SinTheta);
/*************************************************/
for(i = 0; i < nHeight; i++)
{
for(j = 0; j < nWidth;j++)
{
pDib->m_lpImage[i*nWidth+j]=pUnchEdge[i*nWidth+j];
}
}
/*************************************************/
// 释放内存
delete []pUnchImage;
pUnchImage = NULL;
delete []pUnchEdge;
pUnchEdge = NULL;
delete []CosTheta;
CosTheta = NULL;
delete []SinTheta;
SinTheta = NULL;
/*************************************************/
// 恢复光标
EndWaitCursor();
// 设置脏标记
pDoc->SetModifiedFlag(TRUE);
// 更新视图
pDoc->UpdateAllViews(NULL);
}
void CHongmoView::OnCaozuoDingwei()
{
// TODO: Add your command handler code here
CHongmoDoc * pDoc = (CHongmoDoc *)this->GetDocument();
CDib * pDib = pDoc->m_pDibInit;
LPBITMAPINFOHEADER lpBMIH=pDib->m_lpBMIH;
// 判断是否是8-bpp位图
if (lpBMIH->biBitCount != 8)
{
// 提示用户
MessageBox("目前只支持256色位虹膜图像的边缘检测!", "系统提示" ,
MB_ICONINFORMATION | MB_OK);
// 返回
return;
}
//更改光标形状
BeginWaitCursor();
/*************************************************/
//循环变量
int i;
int j;
/*************************************************/
CSize sizeImage = pDib->GetDimensions();
int nWidth = sizeImage.cx;
int nHeight= sizeImage.cy;
int nSaveWidth = pDib->GetDibSaveDim().cx;
// 开辟内存,存储图象数据
unsigned char * pUnchImage = new unsigned char[nWidth*nHeight];
unsigned char* HoughImage = new unsigned char[nWidth*nHeight];
for(i=0; i<nHeight; i++)
{
for(j=0; j<nWidth; j++)
{
pUnchImage[i*nWidth+j] = pDib->m_lpImage[i*nSaveWidth+j];
}
}
for(i=0; i<nHeight; i++)
{
for(j=0; j<nWidth; j++)
{
HoughImage[i*nWidth+j] = pDib->m_lpImage[i*nSaveWidth+j];
}
}
// canny算子计算后的结果
unsigned char * pUnchEdge = new unsigned char[nWidth*nHeight];
// 导数x的方向指针
double * CosTheta = new double [nWidth*nHeight];
// 导数y的方向指针
double * SinTheta = new double [nWidth*nHeight];
/*************************************************/
// 调用Canny()函数对虹膜图像进行边缘检测
Canny(pUnchImage, nWidth, nHeight, 0.8, 0.44, 0.83, pUnchEdge,CosTheta,SinTheta);
/*************************************************/
// 确定内圆半径范围
int temp1 = 30;
int temp2 = 70;
int temp_2 = 0;
int temp_3 = 0;
int temp_4 = 0;
// 调用Hough()函数提取内圆圆心和半径
Hough(temp1,temp2,nWidth,nHeight,CosTheta,SinTheta,pUnchEdge,temp_2,temp_3,temp_4);
//在原图像上用Bresenham画圆算法生成小圆
Bresenham(temp_2,temp_3,temp_4,nWidth,nHeight,HoughImage);
/*************************************************/
//去除不必要的边界点
for(i = 0; i < nHeight; i++)
{
for(j = 0; j < nWidth; j++)
{
if((i-temp_2)*(i-temp_2)+(j-temp_3)*(j-temp_3)>temp_4*temp_4 && (i-temp_2)*(i-temp_2)+(j-temp_3)*(j-temp_3)<(temp_4+50)*(temp_4+50))
{
pUnchEdge[i*nWidth+j] = 0;
}
}
}
for(i = 0; i < nHeight; i++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -