swarthyparth
swarthyparth

Reputation: 11

cv2.Laplacian vs cv2.filter2d - Different results

I am trying to convolve my grayscale image with various filters. I have used the

cv2.Laplacian(gray, cv2.CV_64F)

and

kernel =np.array([[0, 1, 0] , [1, -4, 1] , [0, 1, 0]])
dst = cv2.filter2D(gray, -1, kernel)

But the results are different.

Can someone elaborate why I am getting different results?

Upvotes: 1

Views: 1761

Answers (1)

Ash
Ash

Reputation: 4718

Since what the implementation of cv2.Laplacian does in that case is exactly to convolve with the [[0, 1, 0], [1, -4, 1], [0, 1, 0]] filter as you do, it seems that the likely culprit is the datatype that your are feeding to cv2.Filter2D.

By using this code

kernel = np.array([[0, 1, 0] , [1, -4, 1] , [0, 1, 0]])
dst1 = cv2.filter2D(im, ddepth=cv2.CV_64F, kernel=kernel)
dst2 = cv2.Laplacian(im, cv2.CV_64F)

you should get

>>> np.all(dst1==dst2)
True

Upvotes: 1

Related Questions