BKH
BKH

Reputation: 31

How to compute Gradient of an image with kernel in python

Using python numpy or scipy I am trying to perform cross-correlation on each pixel of an image using a 3 dimensional kernel. I am more interested in looping into each pixel and applying the kernel and looping in

i am thinking in some way like below, not sure how to complete it

image=cv2.imread("ABC.jpg", cv2.IMREAD_GRAYSCALE)
kernal=(np.ones((3, 3)) / 9) 
width, height = image.shape
destinationImg=image
"""to avoid kernal getting out side of image start in 1 and ending """
for x in xrange(1, width-1):
    for y in xrange(1, height-1):
      destinationImg[x,y]=.............

Upvotes: 0

Views: 2732

Answers (1)

bikz05
bikz05

Reputation: 1605

You should use the OpenCV filter2d function to filter an image with your own custom kernel. Here is a tutorial for the same and here is the link to the official documentation.

Upvotes: 2

Related Questions