OpenCV實(shí)現(xiàn)圖像去噪算法的步驟詳解_第1頁
OpenCV實(shí)現(xiàn)圖像去噪算法的步驟詳解_第2頁
OpenCV實(shí)現(xiàn)圖像去噪算法的步驟詳解_第3頁
OpenCV實(shí)現(xiàn)圖像去噪算法的步驟詳解_第4頁
OpenCV實(shí)現(xiàn)圖像去噪算法的步驟詳解_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

第OpenCV實(shí)現(xiàn)圖像去噪算法的步驟詳解目錄一、函數(shù)參考1、Primal-dual算法2、非局部均值去噪算法三、OpenCV源碼1、源碼路徑2、源碼代碼四、效果圖像示例

一、函數(shù)參考

1、Primal-dual算法

Primal-dualalgorithm是一種用于解決特殊類型的變分問題的算法(即找到一個(gè)函數(shù)來最小化一些泛函)。

特別是由于圖像去噪可以看作是變分問題,因此可以使用原始對(duì)偶算法進(jìn)行去噪,這正是該算法所實(shí)現(xiàn)的。

cv::denoise_TVL1(conststd::vectorMatobservations,Matresult,doublelambda=1.0,intniters=30)

observations該數(shù)組應(yīng)包含要恢復(fù)的圖像的一個(gè)或多個(gè)噪聲版本。result這里將存儲(chǔ)去噪圖像。無需預(yù)先分配存儲(chǔ)空間,必要時(shí)會(huì)自動(dòng)分配。lambda對(duì)應(yīng)于上述公式中的。當(dāng)它被放大時(shí),平滑(模糊)的圖像比細(xì)節(jié)(但可能有更多噪點(diǎn))的圖像更受歡迎。粗略地說,隨著它變小,結(jié)果會(huì)更加模糊,但會(huì)去除更多的異常值。niters算法將運(yùn)行的迭代次數(shù)。當(dāng)然,越多的迭代越好,但是這個(gè)說法很難量化細(xì)化,所以就使用默認(rèn)值,如果結(jié)果不好就增加它。

2、非局部均值去噪算法

使用非局部均值去噪算法,該方法基于一個(gè)簡單的原理:將像素的顏色替換為相似像素顏色的平均值。但是與給定像素最相似的像素根本沒有理由靠近。因此,掃描圖像的大部分以尋找真正類似于想要去噪的像素的所有像素是合法的。執(zhí)行圖像去噪,并進(jìn)行了多種計(jì)算優(yōu)化。噪聲預(yù)期為高斯白噪聲。

cv::cuda::fastNlMeansDenoising(InputArraysrc,OutputArraydst,floath,intsearch_window=21,intblock_size=7,Streamstream=Stream::Null())

cv::fastNlMeansDenoising(InputArraysrc,OutputArraydst,floath=3,inttemplateWindowSize=7,intsearchWindowSize=21)

cv::fastNlMeansDenoising(InputArraysrc,OutputArraydst,conststd::vectorfloath,inttemplateWindowSize=7,intsearchWindowSize=21,int

針對(duì)彩色圖像的fastNlMeansDenoising函數(shù)。

cv::cuda::fastNlMeansDenoisingColored(InputArraysrc,OutputArraydst,floath_luminance,floatphoto_render,intsearch_window=21,intblock_size=7,Streamstream=Stream::Null())

cv::fastNlMeansDenoisingColored(InputArraysrc,OutputArraydst,floath=3,floathColor=3,inttemplateWindowSize=7,intsearchWindowSize=21)

針對(duì)圖像序列的fastNlMeansDenoising函數(shù)。

cv::fastNlMeansDenoisingColoredMulti(InputArrayOfArrayssrcImgs,OutputArraydst,intimgToDenoiseIndex,inttemporalWindowSize,floath=3,floathColor=3,inttemplateWindowSize=7,intsearchWindowSize=21)

cv::fastNlMeansDenoisingMulti(InputArrayOfArrayssrcImgs,OutputArraydst,intimgToDenoiseIndex,inttemporalWindowSize,floath=3,inttemplateWindowSize=7,intsearchWindowSize=21)

cv::fastNlMeansDenoisingMulti(InputArrayOfArrayssrcImgs,OutputArraydst,intimgToDenoiseIndex,inttemporalWindowSize,conststd::vectorfloath,inttemplateWindowSize=7,intsearchWindowSize=21,intnormType=NORM_L2)

執(zhí)行純非局部方法去噪,沒有任何簡化,因此速度不快。

cv::cuda::nonLocalMeans(InputArraysrc,OutputArraydst,floath,intsearch_window=21,intblock_size=7,intborderMode=BORDER_DEFAULT,Streamstream=Stream::Null())

三、OpenCV源碼

1、源碼路徑

opencv\modules\photo\src\denoise_tvl1.cpp

2、源碼代碼

#include"precomp.hpp"

#includevector

#includealgorithm

#defineABSCLIP(val,threshold)MIN(MAX((val),-(threshold)),(threshold))

namespacecv{

classAddFloatToCharScaled{

public:

AddFloatToCharScaled(doublescale):_scale(scale){}

inlinedoubleoperator()(doublea,ucharb){

returna+_scale*((double)b);

private:

double_scale;

usingstd::transform;

voiddenoise_TVL1(conststd::vectorMatobservations,Matresult,doublelambda,intniters){

CV_Assert(observations.size()0niters0lambda

constdoubleL2=8.0,tau=0.02,sigma=1./(L2*tau),theta=1.0;

doubleclambda=(double)lambda;

doubles=0;

constintworkdepth=CV_64F;

inti,x,y,rows=observations[0].rows,cols=observations[0].cols,count;

for(i=1;i(int)observations.size();i++){

CV_Assert(observations[i].rows==rowsobservations[i].cols==cols);

MatX,P=Mat::zeros(rows,cols,CV_MAKETYPE(workdepth,2));

observations[0].convertTo(X,workdepth,1./255);

std::vectorMat_doubleRs(observations.size());

for(count=0;count(int)Rs.size();count++){

Rs[count]=Mat::zeros(rows,cols,workdepth);

for(i=0;initers;i++)

doublecurrsigma=i==01+sigma:sigma;

//P_=P+sigma*nabla(X)

//P(x,y)=P_(x,y)/max(||P(x,y)||,1)

for(y=0;yrows;y++)

constdouble*x_curr=X.ptrdouble

constdouble*x_next=X.ptrdouble(std::min(y+1,rows-1));

Point2d*p_curr=P.ptrPoint2d

doubledx,dy,m;

for(x=0;xcols-1;x++)

dx=(x_curr[x+1]-x_curr[x])*currsigma+p_curr[x].x;

dy=(x_next[x]-x_curr[x])*currsigma+p_curr[x].y;

m=1.0/std::max(std::sqrt(dx*dx+dy*dy),1.0);

p_curr[x].x=dx*m;

p_curr[x].y=dy*m;

dy=(x_next[x]-x_curr[x])*currsigma+p_curr[x].y;

m=1.0/std::max(std::abs(dy),1.0);

p_curr[x].x=0.0;

p_curr[x].y=dy*m;

//Rs=clip(Rs+sigma*(X-imgs),-clambda,clambda)

for(count=0;count(int)Rs.size();count++){

transformMatIterator_double,MatConstIterator_uchar,MatIterator_double,AddFloatToCharScaled(

Rs[count].begin(),Rs[count].end(),observations[count].beginuchar(),

Rs[count].begin(),AddFloatToCharScaled(-sigma/255.0));

Rs[count]+=sigma*X;

min(Rs[count],clambda,Rs[count]);

max(Rs[count],-clambda,Rs[count]);

for(y=0;yrows;y++)

double*x_curr=X.ptrdouble

constPoint2d*p_curr=P.ptrPoint2d

constPoint2d*p_prev=P.ptrPoint2d(std::max(y-1,0));

//X1=X+tau*(-nablaT(P))

x=0;

s=0.0;

for(count=0;count(int)Rs.size();count++){

s=s+Rs[count](y,x);

doublex_new=x_curr[x]+tau*(p_curr[x].y-p_prev[x].y)-tau*s;

//X=X2+theta*(X2-X)

x_curr[x]=x_new+theta*(x_new-x_curr[x]);

for(x=1;xcols;x++)

s=0.0;

for(count=0;count(int)Rs.size();count++){

s+=Rs[count](y,x);

//X1=X+tau*(-nablaT(P))

x_new=x_curr[x]+tau*(p_curr[x].x-p_c

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(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)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論