日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python去噪算法

發(fā)布時間:2025/7/14 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python去噪算法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

《programming computer vision with python 》中denoise 算法有誤,從網(wǎng)上好了可用的代碼貼上,以便以后使用。

書中錯誤的代碼:

def denoise(im,U_init,tolerance=0.1,tau=0.125,tv_weight=100):m,n = im.shapeU = U_initPx = imPy = imerror = 1while (error > tolerance):Uold = UGradUx = roll(U,-1,axis=1)-UGradUy = roll(U,-1,axis=0)-UPxNew = Px + (tau/tv_weight)*GradUxPyNew = Py + (tau/tv_weight)*GradUyNormNew = maximum(1,sqrt(PxNew**2+PyNew**2))Px = PxNew/NormNewpy = PyNew/NormNewRxPx = roll(Px,1,axis=1)RyPy = roll(Py,1,axis=0)DivP = (Px - RxPx) + (Py - RyPy)U = im + tv_weight*DivPerror = linalg.norm(U-Uold)/sqrt(n*m)return U,im-U

網(wǎng)上可用的代碼:

def denoise(im, U_init, tolerance=0.1, tau=0.125, tv_weight=100):""" An implementation of the Rudin-Osher-Fatemi (ROF) denoising modelusing the numerical procedure presented in Eq. (11) of A. Chambolle(2005). Implemented using periodic boundary conditions (essentially turning the rectangular image domain into a torus!).Input:im - noisy input image (grayscale)U_init - initial guess for Utv_weight - weight of the TV-regularizing termtau - steplength in the Chambolle algorithmtolerance - tolerance for determining the stop criterionOutput:U - denoised and detextured image (also the primal variable)T - texture residual"""#---Initializationm,n = im.shape #size of noisy image U = U_initPx = im #x-component to the dual fieldPy = im #y-component of the dual fielderror = 1 iteration = 0#---Main iterationwhile (error > tolerance):Uold = U#Gradient of primal variableLyU = vstack((U[1:,:],U[0,:])) #Left translation w.r.t. the y-directionLxU = hstack((U[:,1:],U.take([0],axis=1))) #Left translation w.r.t. the x-direction GradUx = LxU-U #x-component of U's gradientGradUy = LyU-U #y-component of U's gradient#First we update the dual variblePxNew = Px + (tau/tv_weight)*GradUx #Non-normalized update of x-component (dual)PyNew = Py + (tau/tv_weight)*GradUy #Non-normalized update of y-component (dual)NormNew = maximum(1,sqrt(PxNew**2+PyNew**2))Px = PxNew/NormNew #Update of x-component (dual)Py = PyNew/NormNew #Update of y-component (dual)#Then we update the primal variableRxPx =hstack((Px.take([-1],axis=1),Px[:,0:-1])) #Right x-translation of x-componentRyPy = vstack((Py[-1,:],Py[0:-1,:])) #Right y-translation of y-componentDivP = (Px-RxPx)+(Py-RyPy) #Divergence of the dual field.U = im + tv_weight*DivP #Update of the primal variable#Update of error-measureerror = linalg.norm(U-Uold)/sqrt(n*m);iteration += 1;print iteration, error#The texture residualT = im - Uprint 'Number of ROF iterations: ', iterationreturn U,T

測試代碼:

from numpy import * from numpy import random from scipy.ndimage import filters import rof from scipy.misc import imsaveim = zeros((500,500)) im[100:400,100:400] = 128 im[200:300,200:300] = 255im = im + 30*random.standard_normal((500,500))imsave('synth_ori.pdf',im)U,T = rof.denoise(im,im,0.07)G = filters.gaussian_filter(im,10)imsave('synth_rof.pdf',U) imsave('synth_gaussian.pdf',G)

?

轉(zhuǎn)載于:https://www.cnblogs.com/zhangyonghugo/p/3919323.html

總結(jié)

以上是生活随笔為你收集整理的python去噪算法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。