【发布时间】:2018-01-06 10:48:01
【问题描述】:
我只是在 SciPy 和 Python 中玩转卷积和内核。我使用以下内核进行边缘检测,因为它列在 this wikipedia article:
这是我使用的图像:
我得到的结果非常令人失望:
我用于卷积的代码:
edge = np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]])
results = sg.convolve(img, edge, mode='same')
results[results > 255] = 255
results[results < 0] = 0
...以及我用来读取图像的代码:
img = np.array(Image.open('convolution_test/1.jpg'))
img = img[:, :, 0]
为什么我会得到这些糟糕的结果?
TIA。
【问题讨论】:
-
img的类型是什么。因为如果它是无符号的,这可能会导致下溢。 -
如果将矩阵加载为无符号整数,则结果可能会环绕,使得负数实际上是白色值。
-
但是
scipy.convolve只适用于一维数组? -
@WillemVanOnsem 非常感谢!我检查了
img数组的数据类型,你是对的......它是uint8。我把它改成了int32,瞧!如果您将评论写为答案,我会接受。 :) -
@WillemVanOnsem
scipy.signal.convolve也适用于矩阵。我查过了。
标签: python image-processing scipy convolution