【问题标题】:OpenCV Image Denoising gives: Error: -215:Assertation failedOpenCV 图像去噪给出:错误:-215:断言失败
【发布时间】:2020-03-29 12:47:19
【问题描述】:

尝试使用下面的代码对一个非常简单的图像进行降噪。打印出数据数组时,我得到以下结构,这是预期的,因为图像是灰度的:

[[ 62  62  63 ...  29  16   6]
 [ 75  90 103 ...  21  16  12]
 [ 77 100 118 ...  29  29  30]
 ...
 [ 84  68  56 ...  47  50  53]
 [101  94  89 ...  40  44  48]

这是代码和相关的错误,此时我有点卡住了。有什么建议吗?

import cv2
from matplotlib import pyplot as plt

img = cv2.imread(path,0)
dst = cv2.fastNlMeansDenoising(img,None,10,10,7,21)

plt.subplot(211),plt.imshow(dst)
plt.subplot(212),plt.imshow(img)
plt.show()

____________________________________________________________________
runfile(___, wdir='G:/James Alexander/Python Programs')
Traceback (most recent call last):

  File "<ipython-input-127-ce832752c183>", line 1, in <module>
    runfile('G:/James Alexander/Python Programs/Noiseremoval.py', wdir=___)

  File "___", line 704, in runfile
    execfile(filename, namespace)

  File "___", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "___", line 13, in <module>
    dst = cv2.fastNlMeansDenoising(img,None,10,10,7,21)

error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\photo\src\denoising.cpp:120: error: (-215:Assertion failed) hn == 1 || hn == cn in function 'cv::fastNlMeansDenoising'

【问题讨论】:

    标签: python-3.x image opencv image-processing noise


    【解决方案1】:

    阅读您正在使用的Denoising function 上的文档。有两种方法可以调用该函数,您似乎正在结合使用这两种方法。

    dst = cv.fastNlMeansDenoising(src[, dst[, h[, templateWindowSize[, searchWindowSize]]]])

    或

    dst = cv.fastNlMeansDenoising(src, h[, dst[, templateWindowSize[, searchWindowSize[, normType]]]])

    您使用(src, dst, h, templateWindowSize, searchWindowSize, normType) 调用它,它的参数太多或顺序错误,具体取决于您要使用的方法。

    【讨论】:

    • 谢谢,现在将其更改为dst = cv2.fastNlMeansDenoising(img,None,3,7,11),但是噪声消除甚至没有一点作用,有什么建议应该归咎于哪些参数吗?
    • 您需要更高的过滤强度。有关示例,请参见 this old question/answer about the same function。
    【解决方案2】:

    将参数更改为

    dst = cv2.fastNlMeansDenoising(img, None, 30, 7, 21)
    

    【讨论】:

    • 您能否详细说明一下为什么这可能是解决方案?提供一些关于论点含义的信息将更有可能帮助未来的读者,而不仅仅是作者。
    猜你喜欢
    • 2019-12-04
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 2022-01-14
    • 2020-02-03
    • 1970-01-01
    相关资源
    最近更新 更多