I used python code to find the laplacian of an image with just a general kernel= 1 (using cv2). Now I want to use a new kernel array([0,-1,0][-1,5,-1][0,-1,0])
but not sure how I can implement that using the code I have, or how to write new code calling the kernel.
ksize = 1
scale = 1
delta = 0
ddepth = cv2.CV_64F
img = cv2.imread('/Users//Desktop/Programming/image.tif')
img = cv2.GaussianBlur(img,(3,3),0)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray_lap = cv2.Laplacian(gray,ddepth,ksize = ksize,scale = scale,delta = delta)
dst = cv2.convertScaleAbs(gray_lap)
plt.imshow(dst, cmap = 'gray')
I'm not familiar with Python's OpenCV bindings, but for a custom convolution kernel you'll want filter2D
. Build up the kernel yourself as a 3x3 array. This tutorial is in C++ but it looks helpful.