图像去模糊(逆滤波)
生活随笔
收集整理的這篇文章主要介紹了
图像去模糊(逆滤波)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
引言
圖像模糊是一種拍攝常見的現象,我曾在圖像去模糊(維納濾波)?介紹過。這里不再詳述,只給出物理模型,這里我們仍在頻率域表示?
其中提到最簡單的復原方法是直接做逆濾波(Inverse filter)。?
F??(u,v)=G(u,v)H(u,v)(2)
該除法是陣列操作,即按位除。?
在含有噪聲情況下,將(1)式兩端除以H(u,v)?
F??(u,v)=F(u,v)+N(u,v)H(u,v)(3)
這里N(u,v)未知,式子表明,即使知道退化函數也不能準備復原圖像。還有當退化函數H(u,v)是零或者非常小的值,則N(u,v)H(u,v)很容易支配整個式子。?
下面我將用代碼說明一下逆濾波,這里我采用直接編碼形式。對了,前面我提到過,當噪聲信息比NSR等于0時,此時維娜濾波等同于逆濾波。因此可以直接使用matlab自帶deconvwnr函數,將第三個參數NSR設置成0即可,省事的同學可以試一下。
代碼
<code class="hljs vhdl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">close <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">all</span>; clear <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">all</span>; clc; % Display the original image. I = im2double(imread(<span class="hljs-attribute" style="box-sizing: border-box;">'lena</span>.jpg')); [hei,wid,~] = size(I); subplot(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>),imshow(I); title(<span class="hljs-attribute" style="box-sizing: border-box;">'Original</span> Image (courtesy <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">of</span> MIT)');% Simulate a motion blur. LEN = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">21</span>; THETA = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11</span>; PSF = fspecial(<span class="hljs-attribute" style="box-sizing: border-box;">'motion</span>', LEN, THETA); blurred = imfilter(I, PSF, <span class="hljs-attribute" style="box-sizing: border-box;">'conv</span>', <span class="hljs-attribute" style="box-sizing: border-box;">'circular</span>'); subplot(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>), imshow(blurred); title(<span class="hljs-attribute" style="box-sizing: border-box;">'Blurred</span> Image');% Inverse filter <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">If</span> = fft2(blurred); Pf = fft2(PSF,hei,wid); deblurred = ifft2(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">If</span>./Pf); subplot(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>), imshow(deblurred); title(<span class="hljs-attribute" style="box-sizing: border-box;">'Restore</span> Image')% Simulate additive noise. noise_mean = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; noise_var = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0001</span>; blurred_noisy = imnoise(blurred, <span class="hljs-attribute" style="box-sizing: border-box;">'gaussian</span>', ...noise_mean, noise_var); subplot(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>), imshow(blurred_noisy) title(<span class="hljs-attribute" style="box-sizing: border-box;">'Simulate</span> Blur <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">and</span> Noise')% Try restoration assuming no noise. <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">If</span> = fft2(blurred_noisy); deblurred2 = ifft2(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">If</span>./Pf); subplot(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>), imshow(deblurred2) title(<span class="hljs-attribute" style="box-sizing: border-box;">'Restoration</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">of</span> Blurred Assuming No Noise');% Try restoration <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">with</span> noise <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> known. noisy = blurred_noisy - blurred; Nf = fft2(noisy); deblurred2 = ifft2(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">If</span>./Pf - Nf./Pf); subplot(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>), imshow(deblurred2) title(<span class="hljs-attribute" style="box-sizing: border-box;">'Restoration</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">of</span> Blurred <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">with</span> Noise <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">Is</span> Known')</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li></ul>這里使用了經典的lena圖是灰度圖像,分別對圖像進行運動模糊,逆濾波,運動模糊+高斯噪聲,假定噪聲未知直接逆濾波,噪聲已知逆濾波。
效果
說明
逆濾波對噪聲非常敏感,除非我們知道噪聲的分布情況(事實上,這也很難知道),逆濾波幾乎不可用,可以從二排中間看出,恢復圖像效果極差。但若知道噪聲分布,也是可以完全復原信息的。可以從二排最后一張圖可以看出。寫作本文的目的也僅是在數學角度上對圖像模糊現象進行分析,后續會介紹更加有效的圖像復原方法,敬請關注。
相關閱讀及參考文獻
圖像去模糊(維納濾波)?http://blog.csdn.net/bluecol/article/details/46242355?
圖像去模糊(約束最小二乘濾波)?http://blog.csdn.net/bluecol/article/details/47359421?
數字圖像處理(第三版) 岡薩雷斯著 chapter 5,圖像復原與重建
轉載請保留以下信息
| 風吹夏天 | 2015年8月8日 | wincoder@qq.com |
總結
以上是生活随笔為你收集整理的图像去模糊(逆滤波)的全部內容,希望文章能夠幫你解決所遇到的問題。