How to Compute Image Gradients?
You can create your own custom kernel filter using something similar to this example.

if you just want to find image gradients there are other options such as sobel and laplace

If your aim is edge detection, I find canny is best for this in most cases.