




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、快速中值濾波算法南昌大學(xué)實(shí)驗(yàn)報(bào)告學(xué) 生 姓 名 :洪 僡 婕學(xué)號(hào) :6100411159專(zhuān)業(yè)班級(jí): 數(shù)媒 111 班實(shí)驗(yàn)類(lèi)型: 驗(yàn)證 綜合 設(shè)計(jì) 創(chuàng)新實(shí)驗(yàn)日期: 4.291、 實(shí)驗(yàn)項(xiàng)目名稱(chēng) 數(shù)字圖像處理2、 實(shí)驗(yàn)?zāi)康膶?shí)現(xiàn)快速中值濾波算法 三、實(shí)驗(yàn)內(nèi)容實(shí)驗(yàn)成績(jī):用 vc+實(shí)現(xiàn)中值濾波的快速算法四、主要儀器設(shè)備及耗材pc 機(jī)一臺(tái)五、實(shí)驗(yàn)步驟/ imageprocessingdoc.cpp : implementationof the cimageprocessingdoc class/#include stdafx.h#include imageprocessing.h#include image
2、processingdoc.h#include greyratio.h#include #define pi (acos(0.0) * 2)#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_; #endif/ cimageprocessingdocimplement_dyncreate(cimageprocessingdoc,cdocument)begin_message_map(cimageprocessingdoc,cdocument)/afx_msg_map(cimageproc
3、essingdoc)on_command(id_histogram_adjustifcation,onhistogramadjustifcation)on_command(id_fft, onfft)on_command(id_salt_pepper_noice,onsaltpeppernoice)on_command(id_random_noise,onrandomnoise)on_command(id_median_filtering,onmedianfiltering)on_command(id_dct, ondct)on_command(id_fwt, onfwt)on_command
4、(id_dht, ondht)on_command(id_wavelet_transform,onwavelettransform)on_command(id_grey_adjustifcation,ongreyadjustifcation)on_command(id_grey_linear_adjustifcation, ongreylinearadjustifcation)on_command(id_grey_seglinear_adjustifcation, ongreyseglinearadjustifcation)on_command(id_2dgrad, on2dgrad)on_c
5、ommand(id_robert, onrobert)/afx_msg_mapend_message_map()/ cimageprocessingdocconstruction/destructioncimageprocessingdoc:cimageprocessingdoc()/ todo: add one-time construction code heremimagefile = null;bfileisload = false;nrows = 256;ncols = 256;msourcedata = null;psourcedata = null;bdataisprocesse
6、d = false;mresultdata = false;presultdata = false;fourierdatar = null;fourierdatai = null;cimageprocessingdoc:cimageprocessingdoc()boolcimageprocessingdoc:onnewdocument()if (!cdocument:onnewdocument()return false;/ todo: add reinitialization code here / (sdi documents will reuse thisdocument)return
7、true;/ cimageprocessingdoc serializationvoidcimageprocessingdoc:serialize(carchive&ar) if (ar.isstoring() / todo: add storing code hereelse/ todo: add loading code here/ cimageprocessingdoc diagnostics#ifdef _debugvoid cimageprocessingdoc:assertvalid()constcdocument:assertvalid();voidcimageprocessin
8、gdoc:dump(cdumpcontext&dc) constcdocument:dump(dc);#endif /_debug/ cimageprocessingdoc commandsboolcimageprocessingdoc:onopendocument(lpctstr lpszpathname) int x;int y;if(!cdocument:onopendocument(lpszpathname)return false;/ todo: add your specialized creation code hereif(msourcedata) free(msourceda
9、ta);msourcedata = null;if (!(msourcedata = (unsigned char *)malloc(nrows*ncols*sizeof(unsignedchar)return false;if (psourcedata) free(psourcedata);psourcedata = null;if (!(psourcedata = (unsigned char *)malloc(3*nrows*ncols*sizeof(unsignedchar)return false;if (mresultdata) free(mresultdata);mresultd
10、ata = null;if (!(mresultdata = (unsigned char *)malloc(nrows*ncols*sizeof(unsignedchar)return false;if (presultdata) free(presultdata);presultdata = null;if (!(presultdata = (unsigned char *)malloc(3*nrows*ncols*sizeof(unsignedchar)return false;if (mimagefile) fclose(mimagefile);mimagefile = null;if
11、 (!(mimagefile =fopen(lpszpathname,rb)free(msourcedata);return false;if (fread(msourcedata,sizeof(unsignedchar),nrows*ncols,mimagefile) !=(unsigned)ncols*nrows) free(msourcedata);fclose(mimagefile);mimagefile = null;bfileisload = false;return false;for(y = 0; y nrows; y+)for(x = 0; x ncols; x+)psour
12、cedata3*y*ncols+3*x= msourcedatay*ncols+x;psourcedata3*y*ncols+3*x+1= msourcedatay*ncols+x;psourcedata3*y*ncols+3*x+2= msourcedatay*ncols+x;bfileisload = true;return true;voidcimageprocessingdoc:onhistogramadjustifcation()/ todo: add your command handler code here int x,y;double *mr;double *ms;mr =
13、new double256;ms = new double256;for(x=0;x256;x+)mrx = msx = 0.0;/統(tǒng)計(jì)直方圖for(y = 0; y nrows; y+) for(x = 0; x ncols; x+)mrmsourcedatay*ncols+x +;for(x=0;x256;x+)for(y=0;yx;y+)msx += mry;msx /= nrows*ncols;/ 直方圖變換for(y = 0; y nrows; y+)for(x = 0; x ncols; x+) mresultdatay*nrows+x = (char)(255* msmsourc
14、edatay*nrows+x);/灰度計(jì)算for(y = 0; y nrows; y+)for(x = 0; x ncols; x+)presultdata3*y*ncols+3*x= mresultdatay*ncols+x;presultdata3*y*ncols+3*x+1= mresultdatay*ncols+x;presultdata3*y*ncols+3*x+2= mresultdatay*ncols+x;/更新顯示updateallviews(null);/ fftandifft 一維傅立葉變換與逆變換函數(shù) / 輸入時(shí)域數(shù)據(jù)實(shí)部tr,虛部ti/ 輸出頻域數(shù)據(jù)實(shí)部tr,虛部ti/
15、 序列長(zhǎng)度n,n等于2的r次冪/ fftorifft, 邏輯變量,非零做正變換,零做 反變換voidcimageprocessingdoc:fftandifft(float *tr, float *ti, int n, bool fftorifft) int r; / 迭代次數(shù)int l,j,k;/ 循環(huán)變量int p; / 用于蝶形計(jì)算加權(quán)系數(shù)的指數(shù) int b; / 對(duì)偶結(jié)點(diǎn)距離float x,y,xx,yy;float w;float cosw,sinw;if (!fftorifft) / 如果做傅立葉逆變換, 則必須對(duì)數(shù)列除以 nfor(l=0;ln;l+)trl /= n;til /
16、= n;/ 計(jì)算循環(huán)次數(shù)rr = 0; l = n;while(l /= 2) r+;/ 倒序int lh = n/2;int i;float temp;j = 0;for (i=1;i=k) j = j-k;k = k/2;j = j + k;if (i=j) temp = tri; tri = trj; trj = temp;temp = tii; tii = tij; tij = temp;for(l=0; l = r; l+) / 共r級(jí)b = 1(l-1); / 第l層對(duì)偶結(jié)點(diǎn)距離 為2(l-1)for(j=0; j b;j+)p = j*(1(r-l);w = 2*pi*p/n;f
17、or(k=j;kn-1;k+=(1l) if (fftorifft) / 若做傅立葉正變換cosw =cos(-w);sinw =sin(-w);else / 傅立葉反變換 cosw =cos(w);sinw =sin(w);x = trk + trk+b*cosw - tik+b* sinw;y = tik + trk+b*sinw + tik+b* cosw;xx = trk - trk+b*cosw +tik+b * sinw;yy = tik - trk+b*sinw - tik+b* cosw;trk = x;tik = y;trk+b = xx;tik+b = yy;void ci
18、mageprocessingdoc:onfft()/ todo: add your command handler code here int i,j;int ii,jj;float temp;float *tr;float *ti;tr = new floatncols;ti = new floatncols;if ( fourierdatar) delete fourierdatar;fourierdatar = null;if ( fourierdatai) delete fourierdatai;fourierdatar = null;fourierdatar = new floatn
19、rows*ncols;fourierdatai = new floatnrows*ncols;for(i=0;inrows;i+) for(j=0;jncols;j+) / 圖像數(shù)據(jù)先給傅立葉變換數(shù)組fourierdatari*ncols+j = (float)msourcedatai*ncols+j;fourierdataii*ncols+j = 0.0;for (i=0;inrows;i+) / 每行進(jìn)行傅立 葉變換for (j=0;jncols;j+)trj = fourierdatari*ncols + j; tij = fourierdataii*ncols +j;fftandiff
20、t(tr,ti,ncols,1);for (j=0;jncols;j+) fourierdatari*ncols + j = trj;fourierdataii*ncols + j =tij;delete tr;delete ti;tr = new floatnrows;ti = new floatnrows; for(j=0;jncols;j+) / 每列進(jìn)行傅立葉變換for (i=0;inrows;i+)tri = fourierdatari*ncols + j; tii = fourierdataii*ncols +j;fftandifft(tr,ti,nrows,1);for (i=0
21、;inrows;i+) fourierdatari*ncols + j = tri;fourierdataii*ncols + j =tii;for (i=0;inrows;i+)for (j=0;j 255.0)temp = 255.0;ii = nrows - 1 -(inrows/2?i+nrows/2:i-nrows/2);jj =(jncols/2)?(j+ncols/2):(j-ncols/2);/ 將變換后現(xiàn)實(shí)的原點(diǎn)調(diào)整在中心位 置presultdata3*ii*ncols+3*jj= (int) temp;presultdata3*ii*ncols+3*jj+1= (int)
22、temp;presultdata3*ii*ncols+3*jj+2= (int) temp;/ 更新顯示updateallviews(null);delete fourierdatar;delete fourierdatai;fourierdatai = null;fourierdatar = null;return;voidcimageprocessingdoc:onsaltpeppernoice() / todo: add your command handler code here/ todo: add your command handler code hereint x;int y;
23、salt_pepper_noise(msourcedata,ncols,nrows);for(y = 0; y nrows; y+)for(x = 0; x ncols; x+)psourcedata3*y*ncols+3*x= (unsigned char)msourcedatay*ncols+x;psourcedata3*y*ncols+3*x+1= (unsigned char)msourcedatay*ncols+x;psourcedata3*y*ncols+3*x+2= (unsigned char)msourcedatay*ncols+x;updateallviews(null);
24、voidcimageprocessingdoc:onrandomnoise()/ todo: add your command handler code here int x;int y;random_noise(msourcedata,nrows,ncols); for(y = 0; y nrows; y+)for(x = 0; x ncols; x+)psourcedata3*y*ncols+3*x= (unsigned char)msourcedatay*ncols+x;psourcedata3*y*ncols+3*x+1= (unsigned char)msourcedatay*nco
25、ls+x;psourcedata3*y*ncols+3*x+2= (unsigned char)msourcedatay*ncols+x;updateallviews(null);voidcimageprocessingdoc:salt_pepper_noise(un signed char *mdata, int nheight, int nwidth) unsigned char* lpsrc;/循環(huán)變量long i;long j;/生成偽隨機(jī)種子srand(unsigned)time(null);/在圖像中加噪for (j = 0;j nheight ;j+)for(i = 0;i 31
26、500) / 指向源圖像倒數(shù)第j行,第i個(gè)象素 的指針lpsrc = (unsigned char*)&mdataj*nwidth + i;/圖像中當(dāng)前點(diǎn)置為黑*lpsrc = 0;/ 返回return ;voidcimageprocessingdoc:random_noise(unsigne d char *mdata, int nheight, int nwidth) / 指向源圖像的指針unsigned char* lpsrc;/循環(huán)變量long i;long j;/像素值unsigned char pixel;/噪聲byte noisepoint;/生成偽隨機(jī)種子srand(unsig
27、ned)time(null);/在圖像中加噪for (j = 0;j nheight ;j+)for(i = 0;i nwidth ;i+) noisepoint=rand()/1024;/ 指向源圖像倒數(shù)第j行,第i個(gè)象素的 指針lpsrc = (unsigned char *)&mdatanwidth * j + i;/取得像素值pixel = (unsigned char)*lpsrc;*lpsrc = (unsignedchar)(pixel*224/256 + noisepoint);/ 返回return ;voidcimageprocessingdoc:medianfilterin
28、g(unsi gned char *sourcedata, unsigned char *resultdata,int nheight, int nwidth, int nr)int i,j,m,n,r;unsigned tmp;unsigned char* mdata = new unsigned char(2*nr+1)*(2*nr+1);for (i=0;inrows;i+)for (j=0;jncols;j+)if(inheight-nr-1) |(jnwidth-nr-1)resultdatai*nwidth+j = 0;else for(m=-nr;m=nr;m+)for(n=-n
29、r;n=nr;n+)mdata(m+nr)*(2*nr+1)+n+nr=sourcedata(i+m)*nwidth+(j+n);/ 排序for(m=0;m(2*nr+1)*(2*nr+1)-2;m+)r = 1;for(n=m+1;n(2*nr+1)*(2*nr+1);n+)if (mdatanmdatan+1)tmp =mdatan;mdatan=mdatan+1;mdatan+1=tmp;r=0;if (r)break;mresultdatai*nwidth+j =mdatanr*(2*nr+1)+nr;voidcimageprocessingdoc:onmedianfiltering(
30、)/ todo: add your command handler code here int x;int y;medianfiltering(msourcedata,mresultdata,nrows,ncols,1);for(y = 0; y nrows; y+)for(x = 0; x ncols; x+)presultdata3*y*ncols+3*x= (unsigned char)mresultdatay*ncols+x;presultdata3*y*ncols+3*x+1= (unsigned char)mresultdatay*ncols+x;presultdata3*y*nc
31、ols+3*x+2= (unsigned char)mresultdatay*ncols+x;updateallviews(null);void cimageprocessingdoc:ondct() / todo: add your command handler code herevoid cimageprocessingdoc:onfwt() / todo: add your command handler code here void cimageprocessingdoc:ondht() / todo: add your command handler code here voidc
32、imageprocessingdoc:onwavelettransform()/ todo: add your command handler code here voidcimageprocessingdoc:ongreyadjustifcation() / todo: add your command handler code here voidcimageprocessingdoc:ongreylinearadjustifcation() / todo: add your command handler code here int x;int y;int tmp;cgreyratio m
33、dlg;mdlg.domodal();for(y=0;ynrows;y+)for(x=0;x255?255:tmp;presultdata3*y*ncols+3*x = tmp;presultdata3*y*ncols+3*x+1 = tmp;presultdata3*y*ncols+3*x+2 = tmp;updateallviews(null);voidcimageprocessingdoc:ongreyseglinearadjustifcation() / todo: add your command handler code here void cimageprocessingdoc:
34、on2dgrad() / todo: add your command handler code hereint x;int y;int dx;int dy;int tmp;for(y=0;ynrows-1;y+)for(x=0;x255?255:tmp;presultdata3*y*ncols+3*x = tmp;presultdata3*y*ncols+3*x+1 = tmp;presultdata3*y*ncols+3*x+2 = tmp;updateallviews(null);void cimageprocessingdoc:onrobert() / todo: add your command handler code hereint x;int y;int dx;int dy;int t
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 成長(zhǎng)記錄袋小學(xué)生課件
- 2025年環(huán)保廁所項(xiàng)目合作計(jì)劃書(shū)
- 2025年重鉻酸鈉項(xiàng)目建議書(shū)
- 加強(qiáng)網(wǎng)絡(luò)信息安全保障條例
- 公司股份制實(shí)施方案
- 金融投資顧問(wèn)投資風(fēng)險(xiǎn)提示書(shū)
- 小王子電影故事解讀
- StA-IFN-1-生命科學(xué)試劑-MCE
- 石油庫(kù)區(qū)員工年終總結(jié)
- 2025年太陽(yáng)能熱發(fā)電系統(tǒng)項(xiàng)目合作計(jì)劃書(shū)
- 銷(xiāo)量返點(diǎn)合同范本
- 裝飾施工圖審查要點(diǎn)
- 幼兒園中班下學(xué)期語(yǔ)言繪本-沙灘上
- 家庭生活中的安全隱患及預(yù)防方法
- 食堂炊事員聘用合同
- 電氣工程師生涯人物訪談報(bào)告
- 水力學(xué)電子教案
- 信用信息平臺(tái)建設(shè)方案
- 大地保險(xiǎn)理賠標(biāo)準(zhǔn)
- 車(chē)險(xiǎn)經(jīng)營(yíng)情況分析報(bào)告模板
- 《義務(wù)教育數(shù)學(xué)課程標(biāo)準(zhǔn)(2022年版)》解讀
評(píng)論
0/150
提交評(píng)論