自定义手绘风
原图如下:
(原图:life1.jpg)
代码如下:
from PIL import Image import numpy as np vec_el = np.pi/2.2 vec_az = np.pi/4. depth = 40. im = Image.open('C:\\Users\\邓若言\\Desktop\\life1.jpg').convert('L') a = np.asarray(im).astype('float') grad = np.gradient(a) grad_x, grad_y = grad grad_x = grad_x *depth/100. grad_y = grad_y *depth/100. dx = np.cos(vec_el)*np.cos(vec_az) dy = np.cos(vec_el)*np.sin(vec_az) dz = np.sin(vec_el) A = np.sqrt(grad_x**2 + grad_y**2 + 1.) uni_x = grad_x/A uni_y = grad_y/A uni_z = 1./A a2 = 255*(dx*uni_x + dy*uni_y +dz *uni_z) a2 = a2.clip(0,225) im2 = Image.fromarray(a2.astype('uint8')) im2.save('C:\\Users\\邓若言\\Desktop\\life11.jpg')
效果: