# Revision history [back]

to achieve more similar / better results, you need to:

1: flip the kernel

1  2  1
0  0  0
-1 -2 -3


use:

-1 -2 -1
0  0  0
1  2  3


2: choose a different output depth

assuming your input img is uchar, and the result is the same (-1), negative values will get saturated to 0.

(your numpy code silently converts to float64)

all in all that would make it:

filtered = cv2.filter2D(img, cv2.CV_64F, flipped_kernel)


p.s: like this, the anchor point is still at the kernel center, while your code has it top-left, but imho this is the correct version