資源描述:
《數(shù)字圖像處理報告 vc++》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、原圖:實驗一、線性變化線性變化參數(shù)結(jié)果VisualC++實現(xiàn)BOOLCImgProcess::LinTran(CImgProcess*pTo,doubledFa,doubledFb)8{//首先檢查圖像是否是8位灰度圖像if(m_pBMIH->biBitCount!=8)returnfalse;BYTEgray;//臨時變量,存儲當(dāng)前光標(biāo)像素的灰度值inttarget;//臨時變量,存儲當(dāng)前光標(biāo)像素的目標(biāo)值for(inti=0;ibiHeight;i++){for(intj=0;jbiWidt
2、h;j++){gray=GetGray(j,i);target=dFa*gray+dFb;if(target<0)target=0;if(target>255)target=255;//寫入目標(biāo)圖像pTo->SetPixel(j,i,RGB(target,target,target));}};returntrue;}實驗二、分段線性變化參數(shù)結(jié)果8VisualC++實現(xiàn)BOOLCImgProcess::ParLinTran(CImgProcess*pTo,BYTEx1,BYTEx2,BYTEy1,BYTEy2){//首先檢查圖像的類型
3、if(m_pBMIH->biBitCount!=8)returnfalse;//檢查參數(shù)范圍if(x1>x2)returnfalse;//參數(shù)關(guān)系錯誤,返回錯誤BYTEgray;//臨時變量,存儲當(dāng)前光標(biāo)像素的灰度值inttarget;//臨時變量,存儲當(dāng)前光標(biāo)像素的目標(biāo)值for(inti=0;ibiHeight;i++){for(intj=0;jbiWidth;j++){gray=GetGray(j,i);//按公式運算if(gray<=x1){target=y1*gray/x1;}else
4、if(gray<=x2){target=(y2-y1)*(gray-x1)/(x2-x1)+y1;}else{target=(255-y2)*(gray-x2)/(255-x2)+y2;};if(target<0)target=0;if(target>255)target=255;8//寫入目標(biāo)圖像pTo->SetPixel(j,i,RGB(target,target,target));}}returntrue;}實驗三、直方圖均衡化結(jié)果VisualC++實現(xiàn)BOOLCImgProcess::Histeq(CImgProcess*p
5、To){//首先檢查圖像是否是8位灰度圖像if(m_pBMIH->biBitCount!=8)returnfalse;BYTEgray;//臨時變量,存儲當(dāng)前光標(biāo)像素的灰度值inttarget;//臨時變量,存儲當(dāng)前光標(biāo)像素的目標(biāo)值doublepdHist[256];//臨時變量,存儲灰度直方圖doubledTemp;//臨時變量,存儲累加的直方圖數(shù)據(jù)this->GenHist(pdHist);for(inti=0;ibiHeight;i++){for(intj=0;jbiWidth;j++)
6、{dTemp=0;gray=GetGray(j,i);for(BYTEk=0;k255)target=255;//寫入目標(biāo)圖像pTo->SetPixel(j,i,RGB(target,target,target));}};returntrue;}實驗四、中值濾波參數(shù)結(jié)果8VisualC++實現(xiàn)voidCImgProcess::MedianFilter(CImgProcess
7、*pTo,intnFilterH,intnFilterW,intnFilterMY,intnFilterMX){pTo->InitPixels(0);//初始化目標(biāo)圖像inti,j,k,l;intnHeight=GetHeight();intnWidth=GetWidthPixel();intnGray;int*pAryGray;//鄰域像素數(shù)組pAryGray=newint[nFilterH*nFilterW];//逐行掃描圖像,進(jìn)行中值濾波for(i=nFilterMY;i8、1;i++)//行(除去邊緣幾行){for(j=nFilterMX;j