?? hongmoview.cpp
字號:
for(j = 0; j < nWidth; j++)
{
if((i-temp_2)*(i-temp_2)+(j-temp_3)*(j-temp_3)>(temp_4+80)*(temp_4+80))
{
pUnchEdge[i*nWidth+j] = 0;
}
}
}
for(i = 0; i < nHeight; i++)
{
for(j = 0; j < nWidth; j++)
{
if(i*nWidth+j>(temp_2+temp_4)*nWidth)
{
pUnchEdge[i*nWidth+j] = 0;
}
}
}
/*************************************************/
// 確定外圓半徑范圍
int temp3 = 90;
int temp4 = 120;
int temp_5 = 0;
int temp_6 = 0;
int temp_7 = 0;
// 調用Hough()函數提取外圓圓心和半徑
Hough(temp3,temp4,nWidth,nHeight,CosTheta,SinTheta,pUnchEdge,temp_5,temp_6,temp_7);
//在原圖像上用Bresenham畫圓算法生成大圓
Bresenham(temp_5,temp_6,temp_7,nWidth,nHeight,HoughImage);
/*************************************************/
for(i = 0; i < nHeight; i++)
{
for(j = 0; j < nWidth;j++)
{
pDib->m_lpImage[i*nWidth+j]=HoughImage[i*nWidth+j];
}
}
/*************************************************/
// 釋放內存
delete []pUnchImage;
pUnchImage = NULL;
delete []HoughImage;
HoughImage = NULL;
delete []pUnchEdge;
pUnchEdge = NULL;
delete []CosTheta;
CosTheta = NULL;
delete []SinTheta;
SinTheta = NULL;
/*************************************************/
// 設置臟標記
pDoc->SetModifiedFlag(TRUE);
// 更新視圖
pDoc->UpdateAllViews(NULL);
}
void CHongmoView::OnCaozuoGuiyihua()
{
// 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++)
{
for(j = 0; j < nWidth; j++)
{
if((i-temp_2)*(i-temp_2)+(j-temp_3)*(j-temp_3)>(temp_4+80)*(temp_4+80))
{
pUnchEdge[i*nWidth+j] = 0;
}
}
}
for(i = 0; i < nHeight; i++)
{
for(j = 0; j < nWidth; j++)
{
if(i*nWidth+j>(temp_2+temp_4)*nWidth)
{
pUnchEdge[i*nWidth+j] = 0;
}
}
}
/*************************************************/
// 確定外圓半徑范圍
int temp3 = 90;
int temp4 = 120;
int temp_5 = 0;
int temp_6 = 0;
int temp_7 = 0;
// 調用Hough()函數提取外圓圓心和半徑
Hough(temp3,temp4,nWidth,nHeight,CosTheta,SinTheta,pUnchEdge,temp_5,temp_6,temp_7);
//在原圖像上用Bresenham畫圓算法生成大圓
Bresenham(temp_5,temp_6,temp_7,nWidth,nHeight,HoughImage);
/*************************************************/
// 歸一化后圖像的寬度和高度
int nNewWidth = 1024;
int nNewHeight = 128;
// 存儲歸一化后的圖像
unsigned char *NormalizeImage = new unsigned char[nNewWidth*nNewHeight];
for(i = 0; i < nNewHeight; i++)
{
for(j = 0; j < nNewWidth;j++)
{
NormalizeImage[i*nNewWidth+j] = 0;
}
}
/*************************************************/
// 歸一化
Normalization(NormalizeImage,HoughImage,temp_2,temp_3,temp_4,temp_5,temp_6,temp_7,nWidth,nHeight);
/*************************************************/
// 直方圖均衡
InteEqualize(NormalizeImage,nNewWidth,nNewHeight);
/*************************************************/
m_pDibResult = new CDib(CSize(nNewWidth,nNewHeight), 8);
// 拷貝調色板
memcpy(m_pDibResult->m_lpvColorTable, pDib->m_lpvColorTable, m_pDibResult->m_nColorTableEntries*sizeof(RGBQUAD));
// 應用調色板
m_pDibResult->MakePalette();
// 將指針賦值給CDib類的數據
m_pDibResult->m_lpImage = NormalizeImage;
/**************************************************/
CString strSaveFileType = "位圖文件 (*.bmp)|*.bmp; *.dib|All Files (*.*)|*.*||";
CFileDialog FileDlg(FALSE, "*.bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strSaveFileType);
CFile fileOpen ;
if( FileDlg.DoModal() == IDOK )
{
if(!fileOpen.Open( FileDlg.GetPathName() , CFile::modeCreate|CFile::modeWrite ))
{
AfxMessageBox("cannot create the file to save!");
return;
}
if( !m_pDibResult->Write( &fileOpen ) )
{
return;
}
fileOpen.Close();
}
/**************************************************/
// 顯示歸一化后的圖象
GUIYIHUA* pDlg;
pDlg = new GUIYIHUA(NULL,m_pDibResult);
pDlg->DoModal();
/*************************************************/
// 釋放內存
delete []pUnchImage;
pUnchImage = NULL;
delete []HoughImage;
HoughImage = NULL;
delete []pUnchEdge;
pUnchEdge = NULL;
delete []NormalizeImage;
NormalizeImage = NULL;
delete []CosTheta;
CosTheta = NULL;
delete []SinTheta;
SinTheta = NULL;
}
void CHongmoView::OnCaozuoJunheng()
{
// 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];
}
}
/*************************************************/
//調用InteEqualize()函數進行直方圖均衡
InteEqualize(pUnchImage,nWidth,nHeight);
/*************************************************/
for(i = 0; i < nHeight; i++)
{
for(j = 0; j < nWidth;j++)
{
pDib->m_lpImage[i*nWidth+j]=pUnchImage[i*nWidth+j];
}
}
/*************************************************/
// 釋放內存
delete []pUnchImage;
pUnchImage = NULL;
// 恢復光標
EndWaitCursor();
// 設置臟標記
pDoc->SetModifiedFlag(TRUE);
// 更新視圖
pDoc->UpdateAllViews(NULL);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -