【问题标题】:Deblur an image using scikit-image使用 scikit-image 去模糊图像
【发布时间】:2017-04-22 12:00:40
【问题描述】:

我正在尝试使用skimage.restoration.wiener,但我总是得到一个带有一堆 1(或 -1)的图像,我做错了什么?原图来自Uni of Waterloo

import numpy as np
from scipy.misc import imread
from skimage import color, data, restoration
from scipy.signal import convolve2d as conv2

def main():
  image = imread("/Users/gsamaras/Downloads/boat.tif")
  psf = np.ones((5, 5)) / 25
  image = conv2(image, psf, 'same')
  image += 0.1 * image.std() * np.random.standard_normal(image.shape)

  deconvolved = restoration.wiener(image, psf, 0.00001)
  print deconvolved
  print image

if __name__ == "__main__":
    main()

输出:

[[ 1. -1.  1. ...,  1. -1. -1.]
 [-1. -1.  1. ..., -1.  1.  1.]
 [ 1.  1.  1. ...,  1.  1.  1.]
 ..., 
 [ 1.  1.  1. ...,  1. -1.  1.]
 [ 1.  1.  1. ..., -1.  1. -1.]
 [ 1.  1.  1. ..., -1.  1.  1.]]
[[  62.73526298   77.84202199   94.1563234  ...,   85.12442365
    69.80579057   48.74330501]
 [  74.79638704  101.6248559   143.09978769 ...,  100.07197414
    94.34431216   59.72199141]
 [  96.41589893  132.53865314  161.8286996  ...,  137.17602535
   117.72691238   80.38638741]
 ..., 
 [  82.87641732  122.23168689  146.14129645 ...,  102.01214025
    75.03217549   59.78417916]
 [  74.25240964  100.64285679  127.38475015 ...,   88.04694654
    66.34568789   46.72457454]
 [  42.53382524   79.48377311   88.65000364 ...,   50.84624022
    36.45044106   33.22771889]]

我尝试了几个值。我错过了什么?

【问题讨论】:

  • 如果不使用每个人都可以使用的标准映像,则很难调试。您应该使用clip=False 作为开始,以查看过滤器生成哪种值(如文档中所述,这些值会自动裁剪为-1,1)。也许过滤器希望您准备 0,1 浮点范围内的输入(例如使用 img_as_float),但我不确定;我也会试试这个。备注:在我所知道的所有基于 ML 的公式中,调节变量总是正的。我会害怕使用-100000 之类的东西。如果这用于平衡两个组件,则始终可以使用 pos-vals。
  • 我对该过滤器没有任何理论想法,但请检查文档中的公式并考虑您的平衡变量蜜蜂是否为负值。那么什么样的效果是可能的。也许这是您的问题的原因之一。但我只是猜测。
  • @sascha 已更新,clip=False 必须是答案!您可以检查自己,我已经分享了公开可用图像的链接。那个负值是一次绝望的尝试。我觉得这个值应该接近10^-4,或者什么...1似乎效果最好! :O 你想发表一个答案吗? ;)
  • 我觉得这还不够回答。看起来它真的归结为关于图像表示的假设(0-1 中的浮点数与 0-255 中的浮点数;后者似乎不是一件好事,因为 scikit-learn 中的 0-255 范围通常是我认为是基于 uint8 的)。剪裁也是默认设置,需要对您使用的输入类型进行一些实验。我很高兴它现在对您有用,但我认为还有更多关于这些隐藏假设的发现(我认为文档中有一个特殊部分关于文档中的那些类型和范围)。也许之前的 img_as_float 更简洁
  • 好吧@sascha 图片在链接中,代码也在那里,如果你愿意,你可以自己试试! :)

标签: python numpy image-processing scipy scikit-image


【解决方案1】:

目前我最好的解决方案是:

import numpy as np
#import matplotlib.pyplot as plt
from scipy.misc import imfilter, imread
from skimage import color, data, restoration
from scipy.signal import convolve2d as conv2

def main():
  image = imread("/Users/gsamaras/Downloads/boat.tif")
  #plt.imshow(arr, cmap='gray')
  #plt.show()
  #blurred_arr = imfilter(arr, "blur")
  psf = np.ones((5, 5)) / 25
  image = conv2(image, psf, 'same')
  image += 0.1 * image.std() * np.random.standard_normal(image.shape)

  deconvolved = restoration.wiener(image, psf, 1, clip=False)
  #print deconvolved
  plt.imshow(deconvolved, cmap='gray')
  plt.show()
  #print image

if __name__ == "__main__":
    main()

restoration.wiener() 中更小的值会导致图像看起来像是在其上方放置了不透明的叠加层(例如 this)。另一方面,随着这个值的增长,图像越来越模糊。接近 1 的值似乎效果最好并且可以使图像去模糊。

值得注意的是这个值越小(我的意思是balance,图像尺寸越大。


PS - 我愿意接受新的答案。

【讨论】:

  • 你也可以尝试与[[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]]进行卷积
  • 嗯 @JeruLuke,正如我的 PM 所说,我愿意接受新的答案,所以你可以发布一个,解释你的评论! (= 我也看到你没有对我的答案投赞成票,不管你读过它——这是否意味着我应该删除它?
  • 我通常使用 OpenCV。而且我还没有尝试过你的代码 sn-p。通过不投票,我根本不是说你应该删除它。由于上面提到的矩阵对我有用,所以我想提一下,仅此而已。 :)
猜你喜欢
  • 2019-05-13
  • 1970-01-01
  • 1970-01-01
  • 2013-08-29
  • 2021-08-20
  • 2015-08-13
  • 2013-03-02
  • 2022-10-24
相关资源
最近更新 更多