【发布时间】:2018-11-13 01:24:49
【问题描述】:
import numpy as np
import cv2
import scipy.ndimage as sn
timg = np.array([[0,0,0,0],
[0,0,1,0],
[0,0,0,0],
[0,0,0,0]])
tker = np.array([[1,1,0],
[1,1,1],
[1,1,1]])
scipy.ndimage:
>>> print(sn.morphology.binary_dilation(timg,tker).astype(int))
[[0 1 1 0]
[0 1 1 1]
[0 1 1 1]
[0 0 0 0]]
OpenCV:
>>> print(cv2.dilate(timg.astype(np.uint8), tker.astype(np.uint8)))
[[0 1 1 1]
[0 1 1 1]
[0 0 1 1]
[0 0 0 0]]
似乎 ndimage 将内核放置在图像的一个 1 像素上并将其扩展到内核为 1 的任何位置,而 OpenCV 将内核放置在每个像素上并将其设置为其邻居的最大值(当内核为 1 )。
哪种行为是正确的? Wikipedia's animation 似乎偏爱 OpenCV。如果我调用了错误的函数,有没有办法用 scipy 重现 OpenCV 的行为?
旁注:
- matlab 的行为类似于 scipy
- scipy 的行为也出现在
grey_dilation中(虽然我不希望它改变行为)
【问题讨论】:
-
有没有办法用 scipy 重现 OpenCV 的行为? 当然,只需创建一个自定义内核(OpenCV 中使用的那个)并使用它。
标签: python matlab opencv scipy image-morphology