您好,欢迎访问三七文档
快速中值滤波算法南昌大学实验报告学生姓名:洪僡婕学号:6100411159专业班级:数媒111班实验类型:■验证□综合□设计□创新实验日期:4.29实验成绩:一、实验项目名称数字图像处理二、实验目的实现快速中值滤波算法三、实验内容用VC++实现中值滤波的快速算法四、主要仪器设备及耗材PC机一台五、实验步骤//ImageProcessingDoc.cpp:implementationoftheCImageProcessingDocclass//#includestdafx.h#includeImageProcessing.h#includeImageProcessingDoc.h#includeGreyRatio.h#includemath.h#definePI(acos(0.0)*2)#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CImageProcessingDocIMPLEMENT_DYNCREATE(CImageProcessingDoc,CDocument)BEGIN_MESSAGE_MAP(CImageProcessingDoc,CDocument)//{{AFX_MSG_MAP(CImageProcessingDoc)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_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_COMMAND(ID_ROBERT,OnRobert)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CImageProcessingDocconstruction/destructionCImageProcessingDoc::CImageProcessingDoc(){//TODO:addone-timeconstructioncodeheremImageFile=NULL;bFileIsLoad=FALSE;nRows=256;nCols=256;mSourceData=NULL;pSourceData=NULL;bDataIsProcessed=FALSE;mResultData=FALSE;pResultData=FALSE;FourierDataR=NULL;FourierDataI=NULL;}CImageProcessingDoc::~CImageProcessingDoc(){}BOOLCImageProcessingDoc::OnNewDocument(){if(!CDocument::OnNewDocument())returnFALSE;//TODO:addreinitializationcodehere//(SDIdocumentswillreusethisdocument)returnTRUE;}///////////////////////////////////////////////////////////////////////////////CImageProcessingDocserializationvoidCImageProcessingDoc::Serialize(CArchive&ar){if(ar.IsStoring()){//TODO:addstoringcodehere}else{//TODO:addloadingcodehere}}///////////////////////////////////////////////////////////////////////////////CImageProcessingDocdiagnostics#ifdef_DEBUGvoidCImageProcessingDoc::AssertValid()const{CDocument::AssertValid();}voidCImageProcessingDoc::Dump(CDumpContext&dc)const{CDocument::Dump(dc);}#endif//_DEBUG///////////////////////////////////////////////////////////////////////////////CImageProcessingDoccommandsBOOLCImageProcessingDoc::OnOpenDocument(LPCTSTRlpszPathName){intx;inty;if(!CDocument::OnOpenDocument(lpszPathName))returnFALSE;//TODO:Addyourspecializedcreationcodehereif(mSourceData){free(mSourceData);mSourceData=NULL;}if(!(mSourceData=(unsignedchar*)malloc(nRows*nCols*sizeof(unsignedchar))))returnFALSE;if(pSourceData){free(pSourceData);pSourceData=NULL;}if(!(pSourceData=(unsignedchar*)malloc(3*nRows*nCols*sizeof(unsignedchar))))returnFALSE;if(mResultData){free(mResultData);mResultData=NULL;}if(!(mResultData=(unsignedchar*)malloc(nRows*nCols*sizeof(unsignedchar))))returnFALSE;if(pResultData){free(pResultData);pResultData=NULL;}if(!(pResultData=(unsignedchar*)malloc(3*nRows*nCols*sizeof(unsignedchar))))returnFALSE;if(mImageFile){fclose(mImageFile);mImageFile=NULL;}if(!(mImageFile=fopen(lpszPathName,rb))){free(mSourceData);returnFALSE;}if(fread(mSourceData,sizeof(unsignedchar),nRows*nCols,mImageFile)!=(unsigned)nCols*nRows){free(mSourceData);fclose(mImageFile);mImageFile=NULL;bFileIsLoad=false;returnFALSE;}for(y=0;ynRows;y++){for(x=0;xnCols;x++){pSourceData[3*y*nCols+3*x]=mSourceData[y*nCols+x];pSourceData[3*y*nCols+3*x+1]=mSourceData[y*nCols+x];pSourceData[3*y*nCols+3*x+2]=mSourceData[y*nCols+x];}bFileIsLoad=TRUE;returnTRUE;}voidCImageProcessingDoc::OnHistogramAdjustifcation(){//TODO:Addyourcommandhandlercodehereintx,y;double*mR;double*mS;mR=newdouble[256];mS=newdouble[256];for(x=0;x256;x++){mR[x]=mS[x]=0.0;}//统计直方图for(y=0;ynRows;y++){for(x=0;xnCols;x++){mR[mSourceData[y*nCols+x]]++;}for(x=0;x256;x++){for(y=0;yx;y++)mS[x]+=mR[y];mS[x]/=nRows*nCols;}//直方图变换for(y=0;ynRows;y++)for(x=0;xnCols;x++)mResultData[y*nRows+x]=(char)(255*mS[mSourceData[y*nRows+x]]);//灰度计算for(y=0;ynRows;y++){for(x=0;xnCols;x++){pResultData[3*y*nCols+3*x]=mResultData[y*nCols+x];pResultData[3*y*nCols+3*x+1]=mResultData[y*nCols+x];pResultData[3*y*nCols+3*x+2]=mResultData[y*nCols+x];}//更新显示UpdateAllViews(NULL);}//FFTandIFFT一维傅立叶变换与逆变换函数//输入时域数据实部Tr,虚部Ti//输出频域数据实部Tr,虚部Ti//序列长度N,N等于2的r次幂//FFTorIFFT,逻辑变量,非零做正变换,零做反变换voidCImageProcessingDoc::FFTandIFFT(float*Tr,float*Ti,intN,boolFFTorIFFT){intr;//迭代次数intl,j,k;//循环变量intp;//用于蝶形计算加权系数的指数intB;//对偶结点距离floatX,Y,XX,YY;floatw;floatcosw,sinw;if(!FFTorIFFT){//如果做傅立叶逆变换,则必须对数列除以Nfor(l=0;lN;l++){Tr[l]/=N;Ti[l]/=N;}}//计算循环次数rr=0;l=N;while(l/=2)r++;//倒序intLH=N/2;inti;floattemp;j=0;for(i=1;iN-1;i++){k=LH;while(j=k){j=j-k;k=k/2;}j=j+k;if(i=j){temp=Tr[i];Tr[i]=Tr[j];Tr[j]=temp;temp=Ti[i];Ti[i]=Ti[j];Ti[j]=temp;}}for(l=0;
本文标题:快速中值滤波算法
链接地址:https://www.777doc.com/doc-5626094 .html