彩铅风格图像

2022-05-29 09:50:57 浏览数 (2)

代码语言:javascript复制
import cv2
import numpy as np
image=cv2.imread("C:/Users/xpp/Desktop/Lena.png")
cv2.imshow("original",image)
gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 
gray=cv2.medianBlur(gray,7) 
edges=cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,9,10)
color=cv2.bilateralFilter(image,1,250,250) 
cartoon=cv2.bitwise_and(color,color,mask=edges)
cv2.imshow("cartoon",cartoon) 
grayImage=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
grayImage=cv2.GaussianBlur(grayImage,(3,3),0)
edgeImage=cv2.Laplacian(grayImage,-1,ksize=5)
edgeImage=255-edgeImage
ret,edgeImage=cv2.threshold(edgeImage,150,255,cv2.THRESH_BINARY)
edgePreservingImage=cv2.edgePreservingFilter(image,flags=2,sigma_s=50,sigma_r=0.4)
output=np.zeros(grayImage.shape)
output=cv2.bitwise_and(edgePreservingImage,edgePreservingImage,mask=edgeImage)
cv2.imshow("dim",output) 
cartoon_image1,cartoon_image2=cv2.pencilSketch(image,sigma_s=60,sigma_r=0.03,shade_factor=0.02)
cv2.imshow("result1",cartoon_image1) 
cv2.imshow("result2",cartoon_image2) 
cv2.waitKey(0) 
cv2.destroyAllWindows()

算法:彩铅风格图像是一种综合了素描和色彩之间的绘画形式。首先找到图像的边缘并使用双边滤波器和位操作符制作图像,接着用一个边缘保持滤波器来模糊图像并在边缘上加入一个阈值,然后运用风格化的手法,最后创建彩色和黑白的铅笔素描草图形象。

文献:潘龙, 纪庆革, & 陈靖. (2017). 线积分卷积与双色调映射相结合的彩色素描模拟方法. 中国图象图形学报, 22(7), 11.

0 人点赞