How to make a new filter and apply it on an image using cv2 in python2.7?
For example:
kernel = np.array([[-1, -1, -1],
[-1, 4, -
As far as applying a custom kernel to a given image you may simply use filter2D method to feed in a custom filter. You may also copy the following code to get you going. But The results with current filter seem a bit weird:
import cv2
import numpy as np
# Create a dummy input image.
canvas = np.zeros((100, 100), dtype=np.uint8)
canvas = cv2.circle(canvas, (50, 50), 20, (255,), -1)
kernel = np.array([[-1, -1, -1],
[-1, 4, -1],
[-1, -1, -1]])
dst = cv2.filter2D(canvas, -1, kernel)
cv2.imwrite("./filtered.png", dst)
Input image:
Output Image:
EDIT: As per the edits suggested by @Dolphin, using a kernel with center value of 8, would get the good results in case of circular binary disc.