The opencv cv2.Laplacian() function is supposed to be using the kernel
[[0, 1, 0] ,
[1, -4, 1] ,
[0, 1, 0]]
or ideally (noting that the central point sign might be opposite to the outer points which is acceptable since we are normally interested in the absolute value of the filter mask response)
[[-1, -1, -1] ,
[ -1, 8, -1] ,
[ -1, -1, -1]]
However, it appears to be using the kernel
[[ 2, 0, 2] ,
[ 0, -8, 0] ,
[ 2, 0, 2]]
This can be demonstrated by calling cv2.Laplacian(v, ddepth=3, ksize=3) on
v = np.array([
[0, 0, 0, 0, 0, 0, 0, ],
[0, 0, 0, 0, 0, 0, 0, ],
[0, 0, 0, 1, 0, 0, 0, ],
[0, 0, 0, 0, 0, 0, 0, ],
[0, 0, 0, 0, 0, 0, 0, ],
])
v = v.astype(np.uint8)
which gives output as
array([[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 2, 0, 2, 0, 0],
[ 0, 0, 0, -8, 0, 0, 0],
[ 0, 0, 2, 0, 2, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0]], dtype=int16)
can anyone advise which mask is in fact being used and why? The results can be quite different when the underlying kernel shape is different to what is stated or expected.
