使用numpy和PIL实现图像的手绘效果-LMLPHP
输入
使用numpy和PIL实现图像的手绘效果-LMLPHP
输出
使用numpy和PIL实现图像的手绘效果-LMLPHP
代码如下

图像的手绘效果的实现

from PIL import Image
import numpy as np
a = np.array(Image.open("index.jpg").convert('L')).astype('float')
depth = 10
grad = np.gradient(a)
grad_x,grad_y = grad
grad_x = grad_xdepth/100.
grad_y = grad_y
depth/100.
A = np.sqrt(grad_x2 + grad_y2 +1.)
uni_x = grad_x/A
uni_y = grad_y/A
uni_z = 1./A

vec_el = np.pi/2.2
vec_az = np.pi/4.
dx = np.cos(vec_el)np.cos(vec_az)
dy = np.cos(vec_el)
np.sin(vec_az)
dz = np.sin(vec_el)

b = 255(dxuni_x + dyuni_y + dzuni_z)
b = b.clip(0,255)

im = Image.fromarray(b.astype('uint8'))
im.save("index2.jpg")

05-27 04:29