本文旨在为用户提供在图像上应用滤镜的必要工具。我们特别探索了四种滤镜:铅笔素描、暖色效果、冷色效果,以及卡通效果。
图像滤镜
铅笔素描
首先,我们定义铅笔素描的函数:
def PencilSketch(image):
# Convert the image to Grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Remove Noise using Gaussian Blur
blurred_image = cv2.GaussianBlur(gray_image, (21, 21), 0, 0)
# Divide the image
final_image = cv2.divide(gray_image, blurred_image, scale=256)
# Thresholding
ret, mask = cv2.threshold(final_image, 70, 255, cv2.THRESH_BINARY)
# Bitwise operation
sketched_image = cv2.bitwise_and(mask, final_image)
return sketched_image
我们现在可以简单地调用该函数并将图像传递给它,并使用*cv2.imshow()*显示输出草图:
path = '../Images and Videos/Image01 - Kids.jpg'
image = cv2.imread(path)
cv2.imshow('Original Ima