數(shù)字圖像處理實(shí)驗(yàn)?zāi)K.doc_第1頁
數(shù)字圖像處理實(shí)驗(yàn)?zāi)K.doc_第2頁
數(shù)字圖像處理實(shí)驗(yàn)?zāi)K.doc_第3頁
數(shù)字圖像處理實(shí)驗(yàn)?zāi)K.doc_第4頁
數(shù)字圖像處理實(shí)驗(yàn)?zāi)K.doc_第5頁
已閱讀5頁,還剩23頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

數(shù)字圖像處理實(shí)驗(yàn)?zāi)K/ jihanfeiDoc.cpp : implementation of the CJihanfeiDoc class/#include stdafx.h#include jihanfei.h#include math.h#include jihanfeiDoc.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CJihanfeiDocIMPLEMENT_DYNCREATE(CJihanfeiDoc, CDocument)BEGIN_MESSAGE_MAP(CJihanfeiDoc, CDocument)/AFX_MSG_MAP(CJihanfeiDoc)ON_COMMAND(ID_fei, Onfei)ON_COMMAND(ID_niu, Onniu)ON_COMMAND(ID_ji, Onji)ON_COMMAND(ID_a, Ona)ON_COMMAND(ID_b, Onb)ON_COMMAND(ID_zq, Onzq)ON_COMMAND(ID_count, Oncount)ON_COMMAND(ID_neibor, Onneibor)ON_COMMAND(ID_neibor8, Onneibor8)ON_COMMAND(ID_mneibor, Onmneibor)ON_COMMAND(ID_gaosi, Ongaosi)ON_COMMAND(ID_center, Oncenter)ON_COMMAND(ID_layer, Onlayer)ON_COMMAND(ID_one, Onone)ON_COMMAND(ID_two, Ontwo)ON_COMMAND(ID_Robert, OnRobert)ON_COMMAND(ID_Sobel, OnSobel)ON_COMMAND(ID_zhijie, Onzhijie)ON_COMMAND(ID_erjie, Onerjie)ON_COMMAND(ID_average, Onaverage)ON_COMMAND(ID_Hough, OnHough)ON_COMMAND(ID_gaositidu, Ongaositidu)ON_COMMAND(ID_trail, Ontrail)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CJihanfeiDoc construction/destructionCJihanfeiDoc:CJihanfeiDoc()/ TODO: add one-time construction code hereCJihanfeiDoc:CJihanfeiDoc()BOOL CJihanfeiDoc:OnNewDocument()if (!CDocument:OnNewDocument()return FALSE;/ TODO: add reinitialization code here/ (SDI documents will reuse this document)return TRUE;/ CJihanfeiDoc serializationvoid CJihanfeiDoc:Serialize(CArchive& ar)if (ar.IsStoring()/ TODO: add storing code hereelse/ TODO: add loading code here/ CJihanfeiDoc diagnostics#ifdef _DEBUGvoid CJihanfeiDoc:AssertValid() constCDocument:AssertValid();void CJihanfeiDoc:Dump(CDumpContext& dc) constCDocument:Dump(dc);#endif /_DEBUG/ CJihanfeiDoc commandsBOOL CJihanfeiDoc:OnOpenDocument(LPCTSTR lpszPathName) if (!CDocument:OnOpenDocument(lpszPathName)return FALSE;if (!m_Dib.Read_8BitsGray_Image(lpszPathName)/ 判斷讀取文件是否成功CString strMsg;/ 失敗,可能非BMP格式strMsg = 讀取圖像時(shí)出錯(cuò)!可能是不支持該類型的圖像文件!;/ 提示出錯(cuò)MessageBox(NULL, strMsg, 系統(tǒng)提示, MB_ICONINFORMATION | MB_OK);return FALSE;/ 返回FALSEelsem_Dib.MakePalette();SetPathName(lpszPathName);/ 設(shè)置文件名稱SetModifiedFlag(FALSE);/ 初始化臟標(biāo)記為FALSEreturn TRUE;/ 返回TRUEreturn TRUE;BOOL CJihanfeiDoc:CanCloseFrame(CFrameWnd* pFrame) / TODO: Add your specialized code here and/or call the base classreturn CDocument:CanCloseFrame(pFrame);void CJihanfeiDoc:Onfei() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)float temp=0.0f;/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;float fSlope=1.4f;float fIntercept=20.0f;for (i=0;iiHeight;i+)for (j=0;j128)*lpPixel=255;else*lpPixel=0;UpdateAllViews(NULL);return;void CJihanfeiDoc:Onniu() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)float temp=0.0f;/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;float fSlope=1.4f;float fIntercept=20.0f;for (i=0;iiHeight;i+)for (j=0;jiWidth;j+)/讀取每象素存儲(chǔ)位置lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;/ 以下位置填寫代碼實(shí)現(xiàn)線性變換*lpPixel=255-*lpPixel;UpdateAllViews(NULL);return;void CJihanfeiDoc:Onji() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)float temp=0.0f;/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;float fSlope=1.4f;float fIntercept=20.0f;long plcount256;for (i=0;iiHeight;i+)for (j=0;jiWidth;j+)/讀取每象素存儲(chǔ)位置lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;plcount*(lpPixel)+;/ 以下位置填寫代碼實(shí)現(xiàn)線性變換UpdateAllViews(NULL);return;void CJihanfeiDoc:Ona() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)float temp=0.0f;/ 臨時(shí)變量float dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;double fSlope=1.4;double fIntercept=20.0;for (i=0;iiHeight;i+)for (j=0;j255.0)*lpPixel = 255;else if (temp0.0)*lpPixel = 0;else*lpPixel = (unsigned char) (temp+0.5);UpdateAllViews(NULL);return;void CJihanfeiDoc:Onb() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)float temp=0.0f;/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;double fSlope=0.4;double fIntercept=20.0;for (i=0;iiHeight;i+)for (j=0;j255.0)*lpPixel = 255;else if (temp0.0)*lpPixel = 0;else*lpPixel = (unsigned char) (temp+0.5);UpdateAllViews(NULL);return;void CJihanfeiDoc:Onzq() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;long plcount256;long laycount256;for (i= 0; i256; i+)/ 計(jì)數(shù)清空為0plcounti=0;for (i=0;iiHeight;i+) for (j=0;jiWidth;j+)lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;plcount*lpPixel+; double temp=0;for (i= 0; i255) laycounti = 255;for (i=0;iiHeight;i+)for (j=0;jiWidth;j+)/讀取每象素存儲(chǔ)位置lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;*(lpPixel)=unsigned char(laycount*(lpPixel);UpdateAllViews(NULL);return;/統(tǒng)計(jì)量算法增強(qiáng)void CJihanfeiDoc:Oncount() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;float oave;/ 源圖像灰度均值,依據(jù)實(shí)際圖像賦值float ostd;/ 源圖像灰度標(biāo)準(zhǔn)差,依據(jù)實(shí)際圖像賦值float nave=150;/ 增強(qiáng)后圖像的灰度均值,依據(jù)實(shí)際要求賦值float nstd=64;/ 增強(qiáng)后圖像的灰度標(biāo)準(zhǔn)差,依據(jù)實(shí)際要求賦值float temp;float a;float b;float sum1=0,sum2=0;for (i=0;iiHeight;i+)for (j=0;jiWidth;j+)/讀取每象素存儲(chǔ)位置lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;sum1+=*lpPixel;oave=sum1/(iHeight*iWidth);for (i=0;iiHeight;i+)for (j=0;jiWidth;j+)/讀取每象素存儲(chǔ)位置lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;sum2+=float(fabs(*lpPixel-oave)*(fabs(*lpPixel-oave);ostd=sum2/(iHeight*iWidth);a=float(sqrt(nstd/ostd);b=nave-a*oave;for (i=0;iiHeight;i+)for (j=0;j255.0)*lpPixel = 255;else if (temp0.0)*lpPixel = 0;else*lpPixel = (unsigned char) (temp+0.5);UpdateAllViews(NULL);return;/四鄰域?yàn)V波void CJihanfeiDoc:Onneibor() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;for (i=1;iiHeight-1;i+)for (j=1;jiWidth-1;j+)/讀取每象素存儲(chǔ)位置lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;*lpPixel=(*(lpPixel+iBitsWidth)+*(lpPixel-iBitsWidth)+*(lpPixel+1)+*(lpPixel-1)/4;UpdateAllViews(NULL);return;/8鄰域?yàn)V波void CJihanfeiDoc:Onneibor8() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;for (i=1;iiHeight-1;i+)for (j=1;jiWidth-1;j+)/讀取每象素存儲(chǔ)位置lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;*lpPixel=(*(lpPixel-iBitsWidth-1)+*(lpPixel-iBitsWidth+1)+*(lpPixel+iBitsWidth-1)+*(lpPixel+iBitsWidth+1)+*(lpPixel+iBitsWidth)+*(lpPixel-iBitsWidth)+*(lpPixel+1)+*(lpPixel-1)/8;UpdateAllViews(NULL);return;/多鄰域?yàn)V波void CJihanfeiDoc:Onmneibor() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針unsigned char * lpPixel2;int i;/ 循環(huán)變量int j;int p,q;double sum=0;intn=3;for (i=n/2;iiHeight-n/2;i+)for (j=n/2;jiWidth-n/2;j+)/讀取每象素存儲(chǔ)位置lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;for(p=i-n/2;p=i+n/2;p+)for(q=j-n/2;q=j+n/2;q+)lpPixel2=(unsigned char*)(lpStartBit + (iHeight-1-p) * iBitsWidth + q);sum+=*lpPixel2;*lpPixel=unsigned char(sum/(n*n);sum=0;UpdateAllViews(NULL);return;/高斯濾波void CJihanfeiDoc:Ongaosi() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;for (i=1;iiHeight-1;i+)for (j=1;jiWidth-1;j+)/讀取每象素存儲(chǔ)位置lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;*lpPixel=(*(lpPixel-iBitsWidth-1)+*(lpPixel-iBitsWidth+1)+*(lpPixel+iBitsWidth-1)+*(lpPixel+iBitsWidth+1)+*(lpPixel+iBitsWidth)*3+*(lpPixel-iBitsWidth)*3+*(lpPixel+1)*3+*(lpPixel-1)*3+*lpPixel*8)/24;UpdateAllViews(NULL);return;/中值濾波void CJihanfeiDoc:Oncenter() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針unsigned char * lpPixel2;int i;/ 循環(huán)變量int j;int p,q;char temp;double sum=0;intn=3;for (i=n/2;iiHeight-n/2;i+)for (j=n/2;jiWidth-n/2;j+)/讀取每象素存儲(chǔ)位置lpPixel=(unsigned char*)lpStartBit + (iHeight-1-i) * iBitsWidth + j;for(p=i-n/2;pi+n/2;p+)for(q=j-n/2;q(*(lpPixel2+1)temp=*lpPixel2;*lpPixel2=*(lpPixel2+1);*(lpPixel2+1)=temp;if(*lpPixel5)*lpPixel=*(lpPixel2-n/2*iBitsWidth-n/2);else*lpPixel=*lpPixel;UpdateAllViews(NULL);return;/梯度法銳化void CJihanfeiDoc:Onlayer() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;char x;char y;char p;for (i=0;iiHeight-1;i+)for (j=0;j80)*lpPixel=255;else *lpPixel=0;UpdateAllViews(NULL);return;/水平方向微分算子void CJihanfeiDoc:Onone() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;for (i=1;iiHeight-1;i+)for (j=1;j130)*lpPixel=255;else*lpPixel=0;UpdateAllViews(NULL);return;/垂直方向微分算子void CJihanfeiDoc:Ontwo() / TODO: Add your command handler code hereLPSTR lpStartBit = m_Dib.GetPixelBit();/ 象素起始位置指針if (lpStartBit = NULL)/ 找不到象素起始位置指針return ;/ 返回FALSEint iWidth = m_Dib.GetWidth();/ 圖象寬度int iHeight = m_Dib.GetHeight();/ 圖象高度int iBitsWidth = m_Dib.GetBitsWidth();/ 圖象中每行的字節(jié)數(shù)/ 臨時(shí)變量double dtemp=0;/ 臨時(shí)變量 unsigned char * lpPixel;/ 指向源DIB圖像象素位置的指針int i;/ 循環(huán)變量int j;for (i=1;iiHeight-1;i+)for (j=1;j130)*lpPixel=255;else *lpPixel=0;UpdateAllViews(NULL);return;/Robert算子銳化void CJihanfeiDoc:OnRobert() / TODO:

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論