版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、快速中值滤波算法 南昌大学实验报告学生姓名: 洪僡婕 学 号: 专业班级: 数媒111班 实验类型: 验证 综合 设计 创新 实验日期: 4.29 实验成绩: 一、实验项目名称 数字图像处理二、实验目的 实现快速中值滤波算法三、实验内容 用VC+实现中值滤波的快速算法四、主要仪器设备及耗材 PC机一台五、实验步骤/ ImageProcessingDoc.cpp : implementation of the CImageProcessingDoc class/#include stdafx.h#include ImageProcessing.h#include ImageProcessingD
2、oc.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(CImageProcessingDo
3、c)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(ID_
4、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_COM
5、MAND(ID_ROBERT, OnRobert)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CImageProcessingDoc construction/destructionCImageProcessingDoc:CImageProcessingDoc()/ TODO: add one-time construction code here mImageFile = NULL; bFileIsLoad = FALSE;nRows = 256;nCols = 256;mSourceData = NULL; pSourceData = NULL;bDataIsProces
6、sed = FALSE; mResultData = FALSE; pResultData = FALSE;FourierDataR = NULL;FourierDataI = NULL;CImageProcessingDoc:CImageProcessingDoc()BOOL CImageProcessingDoc:OnNewDocument()if (!CDocument:OnNewDocument()return FALSE;/ TODO: add reinitialization code here/ (SDI documents will reuse this document)re
7、turn TRUE;/ CImageProcessingDoc serializationvoid CImageProcessingDoc:Serialize(CArchive& ar) if (ar.IsStoring()/ TODO: add storing code hereelse/ TODO: add loading code here/ CImageProcessingDoc diagnostics#ifdef _DEBUGvoid CImageProcessingDoc:AssertValid() constCDocument:AssertValid();void CImageP
8、rocessingDoc:Dump(CDumpContext& dc) constCDocument:Dump(dc);#endif /_DEBUG/ CImageProcessingDoc commandsBOOL CImageProcessingDoc:OnOpenDocument(LPCTSTR lpszPathName) int x;int y; if (!CDocument:OnOpenDocument(lpszPathName)return FALSE;/ TODO: Add your specialized creation code here if(mSourceData) f
9、ree(mSourceData);mSourceData = NULL;if (!(mSourceData = (unsigned char *)malloc(nRows*nCols*sizeof(unsigned char)return FALSE; if (pSourceData) free(pSourceData); pSourceData = NULL;if (!(pSourceData = (unsigned char *)malloc(3*nRows*nCols*sizeof(unsigned char)return FALSE; if (mResultData) free(mRe
10、sultData);mResultData = NULL;if (!(mResultData = (unsigned char *)malloc(nRows*nCols*sizeof(unsigned char) return FALSE; if (pResultData) free(pResultData);pResultData = NULL;if (!(pResultData = (unsigned char *)malloc(3*nRows*nCols*sizeof(unsigned char)return FALSE;if (mImageFile) fclose(mImageFile
11、);mImageFile = NULL; if (!(mImageFile = fopen(lpszPathName,rb)free(mSourceData);return FALSE;if (fread(mSourceData,sizeof(unsigned char),nRows*nCols,mImageFile) != (unsigned)nCols*nRows) free(mSourceData);fclose(mImageFile);mImageFile = NULL;bFileIsLoad = false;return FALSE; for(y = 0; y nRows; y+)
12、for(x = 0; x nCols; x+) pSourceData3*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;void CImageProcessingDoc:OnHistogramAdjustifcation()/ TODO: Add your command handler code her
13、eint x,y; double *mR;double *mS; mR = new double256;mS = new double256; for(x=0;x256;x+)mRx = mSx = 0.0;/统计直方图 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;
14、x+) mResultDatay*nRows+x = (char) (255* mSmSourceDatay*nRows+x); /灰度计算 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);/ F
15、FTandIFFT 一维傅立叶变换与逆变换函数 / 输入时域数据实部Tr,虚部Ti/ 输出频域数据实部Tr,虚部Ti/ 序列长度N,N等于2的r次幂/ FFTorIFFT,逻辑变量,非零做正变换,零做反变换void CImageProcessingDoc:FFTandIFFT(float *Tr, float *Ti, int N, bool FFTorIFFT) int r; /迭代次数int l,j,k;/循环变量int p; /用于蝶形计算加权系数的指数int B; /对偶结点距离 float X,Y,XX,YY;float w;float cosw,sinw; if (!FFTorIF
16、FT) /如果做傅立叶逆变换,则必须对数列除以Nfor(l=0;lN;l+)Trl /= N;Til /= N; /计算循环次数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级 B = 1(l-1); / 第l层对偶结点
17、距离为2(l-1) for(j=0; j B;j+) p = j*(1(r-l); w = 2*PI*p/N;for(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
18、*sinw - Tik+B * cosw; Trk = X; Tik = Y; Trk+B = XX; Tik+B = YY; void CImageProcessingDoc: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 ( Four
19、ierDataI) delete FourierDataI;FourierDataR = NULL; FourierDataR = new floatnRows*nCols;FourierDataI = new floatnRows*nCols;for(i=0;inRows;i+)for(j=0;jnCols;j+) /图像数据先给傅立叶变换数组 FourierDataRi*nCols+j = (float) mSourceDatai*nCols+j; FourierDataIi*nCols+j = 0.0; for (i=0;inRows;i+) /每行进行傅立叶变换 for (j=0;jn
20、Cols;j+)Trj = FourierDataRi*nCols + j; Tij = FourierDataIi*nCols + j;FFTandIFFT(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+) /每列进行傅立叶变换 for (i=0;inRows;i+)Tri = Fouri
21、erDataRi*nCols + j; Tii = FourierDataIi*nCols + j;FFTandIFFT(Tr,Ti,nRows,1); for (i=0;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); /将
22、变换后现实的原点调整在中心位置 pResultData3*ii*nCols+3*jj = (int) temp; pResultData3*ii*nCols+3*jj+1 = (int) temp; pResultData3*ii*nCols+3*jj+2 = (int) temp; /更新显示 UpdateAllViews(NULL); delete FourierDataR;delete FourierDataI;FourierDataI = NULL;FourierDataR = NULL; return;void CImageProcessingDoc:OnSaltPepperNoic
23、e()/ TODO: Add your command handler code here/ TODO: Add your command handler code here int x;int y;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)
24、 mSourceDatay*nCols+x; pSourceData3*y*nCols+3*x+2 = (unsigned char) mSourceDatay*nCols+x; UpdateAllViews(NULL);void CImageProcessingDoc: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+) pSourceD
25、ata3*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);void CImageProcessingDoc:Salt_Pepper_Noise(unsigned char *mdata, int nHeight, int nWidth
26、) unsigned char*lpSrc;/循环变量long i;long j; /生成伪随机种子srand(unsigned)time(NULL); /在图像中加噪for (j = 0;j nHeight ;j+)for(i = 0;i 31500) / 指向源图像倒数第j行,第i个象素的指针lpSrc = (unsigned char *)&mdataj*nWidth + i;/图像中当前点置为黑*lpSrc = 0;/ 返回return ;void CImageProcessingDoc:Random_Noise(unsigned char *mdata, int nHeight, i
27、nt nWidth) / 指向源图像的指针unsigned char*lpSrc;/循环变量long i;long j; /像素值unsigned char pixel; /噪声BYTE NoisePoint; /生成伪随机种子srand(unsigned)time(NULL); /在图像中加噪for (j = 0;j nHeight ;j+)for(i = 0;i nWidth ;i+)NoisePoint=rand()/1024; / 指向源图像倒数第j行,第i个象素的指针lpSrc = (unsigned char *)&mdatanWidth * j + i;/取得像素值pixel =
28、 (unsigned char)*lpSrc; *lpSrc = (unsigned char)(pixel*224/256 + NoisePoint);/ 返回return ;void CImageProcessingDoc:MedianFiltering(unsigned 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+
29、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=-nR;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+
30、1) tmp = mdatan;mdatan=mdatan+1;mdatan+1 =tmp;r=0; if (r) break; mResultDatai*nWidth+j = mdatanR*(2*nR+1)+nR; void CImageProcessingDoc:OnMedianFiltering() / 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;
31、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*nCols+3*x+2 = (unsigned char) mResultDatay*nCols+x; UpdateAllViews(NULL); void CImageProcessingDoc:OnDct() / TODO: Add your command handler
32、code herevoid CImageProcessingDoc:OnFwt() / TODO: Add your command handler code herevoid CImageProcessingDoc:OnDht() / TODO: Add your command handler code herevoid CImageProcessingDoc:OnWaveletTransform() / TODO: Add your command handler code herevoid CImageProcessingDoc:OnGreyAdjustifcation() / TOD
33、O: Add your command handler code herevoid CImageProcessingDoc:OnGreyLinearAdjustifcation() / TODO: Add your command handler code hereint x;int y;int tmp; CGreyRatio mdlg;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;pResultData
34、3*y*nCols+3*x+2 = tmp; UpdateAllViews(NULL);void CImageProcessingDoc:OnGreySeglinearAdjustifcation() / TODO: Add your command handler code herevoid CImageProcessingDoc: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 tmp; for(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 21715.3-2025健康信息学患者健康卡数据第3部分:有限临床数据
- 内勤培训开训
- 广告门市活动策划方案(3篇)
- 物流货车安全管理制度内容(3篇)
- 起始年级学业水平管理制度(3篇)
- 银行活动内容策划方案(3篇)
- 《GA 888-2010公安单警装备 警用装备包》专题研究报告
- 《GA 655-2006人毛发ABO血型检测解离法》专题研究报告
- 兽医生物制品技术
- 2026年及未来5年市场数据中国背景墙行业市场全景监测及投资战略咨询报告
- 2025年铁岭卫生职业学院单招职业倾向性测试题库新版
- 《煤矿安全生产责任制》培训课件2025
- 项目进度跟进及完成情况汇报总结报告
- 2025年常州机电职业技术学院高职单招语文2018-2024历年参考题库频考点含答案解析
- 民间融资居间合同
- 2024-2025学年冀教版九年级数学上册期末综合试卷(含答案)
- 《智能网联汽车车控操作系统功能安全技术要求》
- 表面活性剂化学知识点
- 公司绿色可持续发展规划报告
- QC成果提高叠合板施工一次验收合格率
- 《塑料材质食品相关产品质量安全风险管控清单》
评论
0/150
提交评论