生活随笔
收集整理的這篇文章主要介紹了
盲去卷积原理及在图像复原的应用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
前言
?????? 之前寫過一篇維納濾波在圖像復(fù)原中的作用,講述了圖像退化模型以及維納濾波的作用。維納濾波使用的前提是知道信號和噪聲的功率譜,但在實際應(yīng)用中較難得到,只能根據(jù)先驗知識進行估計。
?????? 本文介紹盲去卷積復(fù)原算法,并在MATLAB中進行實驗,和維納濾波的復(fù)原效果進行一個對比。盲去卷積的方法有多種,本文主要介紹由fish提出的基于露西-理查德森(Richardson-Lucy)的盲去卷積算法。
盲去卷積原理
?????露西-理查德森算法屬于圖像復(fù)原中的非線性算法,與維納濾波這種較為直接的算法不同,該算法使用非線性迭代技術(shù),在計算量、性能方面都有了一定提升。
?????露西-理查德森算法是由貝葉斯公式推導(dǎo)而來,因為使用了條件概率(即算法考慮了信號的固有波動,因此具有復(fù)原噪聲圖像的能力)。貝葉斯公式如下:
????? 結(jié)合圖像退化/復(fù)原模型,可以得到迭代函數(shù):
??
????其中 fi 就是第i輪迭代復(fù)原圖像,對應(yīng)貝葉斯公式中的p(x),g是退化函數(shù),對應(yīng)貝葉斯公式的p(y|x),c為退化圖像(c(y)dy意為在退化圖像上積分),如果滿足等暈條件,即圖像各區(qū)域的模糊函數(shù)相同,則迭代公式可化簡如下:
???? 這就是路西-理查德森迭代公式,其中c是退化圖像,g是退化函數(shù),f是第k輪復(fù)原圖像。如果系統(tǒng)的退化函數(shù)PSF(g(x))已知,只要有一個初始估計f就可以進行迭代求解了。在開始迭代后,由于算法的形式,估計值會與真實值的差距迅速減小,從而后續(xù)迭代過程f的更新速度會逐漸變慢,直至收斂。算法的另一優(yōu)點就是初始值f>0,后續(xù)迭代值均會保持非負(fù)性,并且能量不會發(fā)散。
?????盲去卷積需要兩步進行復(fù)原,原因是我們既不知道原始圖像f,也不知道退化函數(shù)g。求解過程示意圖如下:
????? 即在第k輪迭代,我們假a設(shè)原始圖像已知,即k-1輪得到的fk-1,再通過R-L公式求解gk,隨后,再用gk求解fk,反復(fù)迭代,最后求得最終f和g。因此,在求解最初,我們需要同時假設(shè)一個復(fù)原圖像f0和一個退化函數(shù)g0。迭代公式如下:
????? 此外,有人采用這種盲去卷積方法進行了相關(guān)實驗,下圖為實驗原圖:
下圖(a)左、右分別為附加標(biāo)準(zhǔn)差1.5%、10%泊松噪聲的退化圖像,圖(b)左、右分別為1.5%的復(fù)原圖像和PSF,圖(c)為10%對應(yīng)結(jié)果
?????
盲去卷積MATLAB實驗
?????將一幅原始圖像,進行模糊處理(模擬大氣湍流),分別使用維納濾波(由于沒加噪聲,就是逆濾波)和盲去卷積進行復(fù)原,復(fù)原結(jié)果如下:
下面是網(wǎng)上找到的有關(guān)盲去卷積的MATLAB程序,可以加深理解。
[plain]?view plaincopy
%%?Deblurring?Images?Using?the?Blind?Deconvolution?Algorithm??? %%盲反卷積算法復(fù)原圖像?? %?The?Blind?Deconvolution?Algorithm?can?be?used?effectively?when?no?? %?information?about?the?distortion?(blurring?and?noise)?is?known.?The?? %?algorithm?restores?the?image?and?the?point-spread?function?(PSF)?? %?simultaneously.?The?accelerated,?damped?Richardson-Lucy?algorithm?is?used?? %?in?each?iteration.?Additional?optical?system?(e.g.?camera)?? %?characteristics?can?be?used?as?input?parameters?that?could?help?to?? %?improve?the?quality?of?the?image?restoration.?PSF?constraints?can?be?? %?passed?in?through?a?user-specified?function?? %在不知道圖像失真信息(模糊和噪聲)信息情況下,盲反卷積算法可以有效地加以利用。該算法?? %對圖像和點擴展函數(shù)(PSF)的同時進行復(fù)原。每次迭代都使用加速收斂Richardson-Lucy??? %算法。額外的光學(xué)系統(tǒng)(如照相機)的特性可作為輸入?yún)?shù),幫助改善圖像復(fù)原質(zhì)量。可以通?? %過用戶指定的函數(shù)對PSF進行限制?? %?Copyright?2004-2005?The?MathWorks,?Inc.?? ??? %%?Step?1:?Read?Image?? %%第一步:讀取圖像?? %?The?example?reads?in?an?intensity?image.?The?|deconvblind|?function?can?? %?handle?arrays?of?any?dimension.?? %該示例讀取一個灰度圖像。|?deconvblind?|函數(shù)可以處理任何維數(shù)組。?? I?=?imread('view.tif');?? figure;imshow(I);title('Original?Image');?? %text(size(I,2),size(I,1)+15,?...?? %????'Image?courtesy?of?Massachusetts?Institute?of?Technology',?...?? %'FontSize',7,'HorizontalAlignment','right');???? ????? ?? ??? %%?Step?2:?Simulate?a?Blur?? %%第二步:模擬一個模糊?? %?Simulate?a?real-life?image?that?could?be?blurred?(e.g.,?due?to?camera?? %?motion?or?lack?of?focus).?The?example?simulates?the?blur?by?convolving?a?? %?Gaussian?filter?with?the?true?image?(using?|imfilter|).?The?Gaussian?filter?? %?then?represents?a?point-spread?function,?|PSF|.?? ?%模擬一個現(xiàn)實中存在的模糊圖像(例如,由于相機抖動或?qū)共蛔?#xff09;。這個例子通過對真實?? %圖像進行高斯濾波器模擬圖像模糊(使用|imfilter|)。高斯濾波器是一個點擴展函數(shù),?? %|PSF|。?? PSF=fspecial('gaussian',7,10);?? Blurred=imfilter(I,PSF,'symmetric','conv');??%對圖像I進行濾波處理;?? figure;imshow(Blurred);title('Blurred?Image');???? ?? ????? ?? ??? %%?Step?3:?Restore?the?Blurred?Image?Using?PSFs?of?Various?Sizes?? %%第三步:使用不同的點擴展函數(shù)復(fù)原模糊圖像?? %?To?illustrate?the?importance?of?knowing?the?size?of?the?true?PSF,?this?? %?example?performs?three?restorations.?Each?time?the?PSF?reconstruction?? %?starts?from?a?uniform?array--an?array?of?ones.?? %為了說明知道真實PSF的大小的重要性,這個例子執(zhí)行三個修復(fù)。PSF函數(shù)重建每次都是從統(tǒng)一?? %的全一數(shù)組開始。?? %%?? %?The?first?restoration,?|J1|?and?|P1|,?uses?an?undersized?array,?|UNDERPSF|,?for?? %?an?initial?guess?of?the?PSF.?The?size?of?the?UNDERPSF?array?is?4?pixels?? %?shorter?in?each?dimension?than?the?true?PSF.??? %第一次復(fù)原,|J1|和|P1|,使用一個較小數(shù)組,|?UNDERPSF?|,來對PSF的初步猜測。該?? %UNDERPSF數(shù)組每維比真實PSF少4個元素。?? UNDERPSF?=?ones(size(PSF)-4);?? [J1?P1]?=?deconvblind(Blurred,UNDERPSF);?? figure;imshow(J1);title('Deblurring?with?Undersized?PSF');??? ?? ????? ?? %%?? %?The?second?restoration,?|J2|?and?|P2|,?uses?an?array?of?ones,?|OVERPSF|,?for?an?? %?initial?PSF?that?is?4?pixels?longer?in?each?dimension?than?the?true?PSF.?? %第二次復(fù)原,|J2|和|P2|,使用一個元素全為1的數(shù)組,|?OVERPSF|,初始PSF每維比真?? %實PSF多4個元素。?? OVERPSF?=?padarray(UNDERPSF,[4?4],'replicate','both');?? [J2?P2]?=?deconvblind(Blurred,OVERPSF);?? figure;imshow(J2);title('Deblurring?with?Oversized?PSF');???? ????? ?? ??? %%?? %?The?third?restoration,?|J3|?and?|P3|,?uses?an?array?of?ones,?|INITPSF|,?for?an?? %?initial?PSF?that?is?exactly?of?the?same?size?as?the?true?PSF.?? %第三次復(fù)原,|J3|和|P3|,使用一個全為一的數(shù)組|?INITPSF?|作為初次PSF,每維與真正?? %的PSF相同。?? INITPSF?=?padarray(UNDERPSF,[2?2],'replicate','both');?? [J3?P3]?=?deconvblind(Blurred,INITPSF);?? figure;imshow(J3);title('Deblurring?with?INITPSF');???? ?? ????? ?? ??? %%?Step?4:?Analyzing?the?Restored?PSF?? %%第四步:分析復(fù)原函數(shù)PSF?? %?All?three?restorations?also?produce?a?PSF.?The?following?pictures?show?? %?how?the?analysis?of?the?reconstructed?PSF?might?help?in?guessing?the?? %?right?size?for?the?initial?PSF.?In?the?true?PSF,?a?Gaussian?filter,?the?? %?maximum?values?are?at?the?center?(white)?and?diminish?at?the?borders?(black).?? %所有這三個復(fù)原也產(chǎn)生PSF。以下圖片顯示對PSF重建分析的如何可能有助于猜測最初PSF的大?? %小。在真正的PSF中,高斯濾波器的最高值在中心(白),到邊界消失(黑)。?? figure;?? subplot(221);imshow(PSF,[],'InitialMagnification','fit');?? title('True?PSF');?? subplot(222);imshow(P1,[],'InitialMagnification','fit');?? title('Reconstructed?Undersized?PSF');?? subplot(223);imshow(P2,[],'InitialMagnification','fit');?? title('Reconstructed?Oversized?PSF');?? subplot(224);imshow(P3,[],'InitialMagnification','fit');?? title('Reconstructed?true?PSF');???? ?? ????? ?? ??? %%??? %?The?PSF?reconstructed?in?the?first?restoration,?|P1|,?obviously?does?not?? %?fit?into?the?constrained?size.?It?has?a?strong?signal?variation?at?the?? %?borders.?The?corresponding?image,?|J1|,?does?not?show?any?improved?clarity?? %?vs.?the?blurred?image,.?? ?%第一次復(fù)原的PSF,|P1|,顯然不適合大小的限制。它在邊界有一個強烈的變化信號。?? %相應(yīng)的圖片|J1|,與模糊圖像|Blurred|比沒有表現(xiàn)出清晰度提高。?? %%?? %?The?PSF?reconstructed?in?the?second?restoration,?|P2|,?becomes?very?smooth?? %?at?the?edges.?This?implies?that?the?restoration?can?handle?a?PSF?of?a?? %?smaller?size.?The?corresponding?image,?|J2|,?shows?some?deblurring?but?it?? %?is?strongly?corrupted?by?the?ringing.?? ?%第二次復(fù)原的PSF,|P2|,邊緣變得非常平滑。這意味著復(fù)原可以處理一個更細(xì)致的?? %PSF。相應(yīng)的圖片|J2|,顯得清晰了,但被一些“振鈴”強烈破壞。?? %%?? %?Finally,?the?PSF?reconstructed?in?the?third?restoration,?|P3|,?is?somewhat?? %?intermediate?between?|P1|?and?|P2|.?The?array,?|P3|,?resembles?the?true?PSF?? %?very?well.?The?corresponding?image,?|J3|,?shows?significant?improvement;?? %?however?it?is?still?corrupted?by?the?ringing.?? ?%最后,第三次復(fù)原的PSF,|P3|,介于|P1|和|P2|之間。該陣列|P3|,非常接近真?? %正的PSF。相應(yīng)的圖片,|J3|,顯示了顯著改善,但它仍然被一些“振鈴”破壞。?? ?? ?? %%?Step?5:?Improving?the?Restoration?? %%第五步:改善圖像復(fù)原?? %?The?ringing?in?the?restored?image,?|J3|,?occurs?along?the?areas?of?sharp?? %?intensity?contrast?in?the?image?and?along?the?image?borders.?This?example?? %?shows?how?to?reduce?the?ringing?effect?by?specifying?a?weighting?? %?function.?The?algorithm?weights?each?pixel?according?to?the?|WEIGHT|?array?? %?while?restoring?the?image?and?the?PSF.?In?our?example,?we?start?by?? %?finding?the?"sharp"?pixels?using?the?edge?function.?By?trial?and?error,?? %?we?determine?that?a?desirable?threshold?level?is?0.3.?? %在復(fù)原圖像|J3|內(nèi)部灰度對比鮮明的地方和圖像邊界都出現(xiàn)了“振鈴”。這個例子說明了如何?? %通過定義一個加權(quán)函數(shù)來減少圖像中的“振鈴”。該算法是在對圖像和PSF進行復(fù)原時,對每個?? %像元根據(jù)|WEIGHT|數(shù)組進行加權(quán)計算。在我們的例子,我們從用邊緣函數(shù)查找“鮮明”像元?? %開始。通過反復(fù)試驗,我們確定理想的閾值為0.3。?? ?? %WEIGHT?=?edge(I,'sobel',.3);???? ?WEIGHT?=?edge(Blurred,'sobel',.3);??? %%?? %?To?widen?the?area,?we?use?|imdilate|?and?pass?in?a?structuring?element,?|se|.?? %為了拓寬領(lǐng)域,我們使用|imdilate|并傳遞一個結(jié)構(gòu)元素|se|。?? se?=?strel('disk',2);?? WEIGHT?=?1-double(imdilate(WEIGHT,se));???? ??? %%?? %?The?pixels?close?to?the?borders?are?also?assigned?the?value?0.?? %在邊界附近像素的值也被分配為0。?? WEIGHT([1:3?end-[0:2]],:)?=?0;?? WEIGHT(:,[1:3?end-[0:2]])?=?0;?? figure;imshow(WEIGHT);title('Weight?array');???? ?? ????? ?? ?%%?? %?The?image?is?restored?by?calling?deconvblind?with?the?|WEIGHT|?array?and?an?? %?increased?number?of?iterations?(30).?Almost?all?the?ringing?is?suppressed.?? %該圖像通過|WEIGHT|數(shù)組和增加重復(fù)次數(shù)(30)調(diào)用deconvblind函數(shù)來復(fù)原。幾乎所?? %有的“振鈴”被抑制。?? [J?P]?=?deconvblind(Blurred,INITPSF,30,[],WEIGHT);?? figure;imshow(J);title('Deblurred?Image');???? ????? ?? ??? %%?Step?6:?Using?Additional?Constraints?on?the?PSF?Restoration?? %第六步:使用附加約束對PSF復(fù)原?? %?The?example?shows?how?you?can?specify?additional?constraints?on?the?PSF.?? %這個例子說明了如何在PSF上指定額外的限制。?? %?The?function,?|FUN|,?below?returns?a?modified?PSF?array?which?deconvblind?? %?uses?for?the?next?iteration.??? %函數(shù)|FUN|返還一個修改了的PSF數(shù)組,用作deconvblind函數(shù)的下一次重復(fù)。?? %?In?this?example,?|FUN|?modifies?the?PSF?by?cropping?it?by?|P1|?and?|P2|?number?? %?of?pixels?in?each?dimension,?and?then?padding?the?array?back?to?its?? %?original?size?with?zeros.?This?operation?does?not?change?the?values?in?? %?the?center?of?the?PSF,?but?effectively?reduces?the?PSF?size?by?|2*P1|?and?? %?|2*P2|?pixels.??? %在這個例子中,通過對PSF數(shù)組各維數(shù)剪切|P1|和|P2|個值實現(xiàn)對PSF的修改,對數(shù)組填充?? %回零。此操作不會改變在PSF中心的值,而且有效地在各維減少了|2*P1|和|?2*P2|元?? %素。?? ??? P1?=?2;?? P2?=?2;?? FUN?=?@(PSF)?padarray(PSF(P1+1:end-P1,P2+1:end-P2),[P1?P2]);???? ??? %%?? %?The?anonymous?function,?|FUN|,?is?passed?into?|deconvblind|?last.?? %該匿名函數(shù)|FUN|,最后傳遞給|?deconvblind?|。?? %%?? %?In?this?example,?the?size?of?the?initial?PSF,?|OVERPSF|,?is?4?pixels?larger?? %?than?the?true?PSF.?Setting?P1=2?and?P2=2?as?parameters?in?|FUN|?? %?effectively?makes?the?valuable?space?in?|OVERPSF|?the?same?size?as?the?true?? %?PSF.?Therefore,?the?outcome,?|JF|?and?|PF|,?is?similar?to?the?result?of?? %?deconvolution?with?the?right?sized?PSF?and?no?|FUN|?call,?|J|?and?|P|,?from?? %?step?4.?? %在這個例子中,初始PSF,|OVERPSF|,每維比真正的PSF多4個像素,。設(shè)置P1=2和P2=2作?? %為|FUN|的參數(shù),可有效地使|OVERPSF|與真正的PSF的大小相同。因此,得到的結(jié)果|JF|?? %和|PF|,與第四步不使用|FUN|而僅用正確尺寸PSF盲反卷積得到的結(jié)果|J|和|P|類似。?? [JF?PF]?=?deconvblind(Blurred,OVERPSF,30,[],WEIGHT,FUN);?? figure;imshow(JF);title('Deblurred?Image');???? ?? ????? ?? ??? %%?? %?If?we?had?used?the?oversized?initial?PSF,?|OVERPSF|,?without?the?? %?constraining?function,?|FUN|,?the?resulting?image?would?be?similar?to?the?? %?unsatisfactory?result,?|J2|,?achieved?in?Step?3.?? %?? %?Note,?that?any?unspecified?parameters?before?|FUN|?can?be?omitted,?such?as?? %?|DAMPAR|?and?|READOUT|?in?this?example,?without?requiring?a?place?holder,?? %?([]).?? ?%如果我們使用了沒有約束的函數(shù)|FUN|的較大的初始PSF,|?OVERPSF?|,所得圖像將類?? %似第3步得到的效果并不理想的|J2|。??? %注意,任何在|FUN|之前未指定參數(shù)都可以省略,如|DAMPAR|和|READOUT|在這個例子中,而不需要指示他們的位置,([])。?? ??? displayEndOfDemoMessage(mfilename) ?
總結(jié)
以上是生活随笔為你收集整理的盲去卷积原理及在图像复原的应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。