Today is the first time to write an article here, is a small sprout new, please big guys a lot of care

Today I’m going to show you how to turn a GIF into a nice hand-drawn image

PIL is used to read the picture and NUMPY is used to process the picture

The complete code is as follows:

from PIL import Image import numpy as np

Vec_el = Np.pi /2.2 # Overlooking Angle of light source

Vec_az = Np.pi /4. # Light source azimuth Angle

depth = 10.

im1 = Image.open(“mayi_50.gif”).convert(‘L’)

A = np.asarray(im1).astype(‘float’) # change to a = np.asarray(image.open (‘ tree.jpg ‘).convert(‘L’)).astype(float)

Grad = Np.gradient (a) # or take the gradient value of the image

Grad_x,grad_y=grad #

Grad_x = grad_x*depth/40

Grad_y = grad_y*depth/40

Dx = Np.cos (vec_EL)* NP.cos (vec_az)# Effect on X-axis of light source

Dy = Np.cos (vec_EL)* NP.cos (vec_az)# Influence on Y axis of light source

Dz = Np.sin (VEC_EL) # Influence on z-axis of light source

A = np.sqrt(grad_x2+grad_y2+1.)

uni_x = grad_x/A

uni_y = grad_y/A

uni_z = 1./A

A2 = 255*(DXUNI_x +dyuni_y+ Dz *uni_z) # Normalization of light source

A2 = a2. The clip (0255).

Im2 = image.fromarray (a2.astype(‘uint8’)) #

Im2. save(‘mayi_51.gif’) # change the name to save

The renderings are as follows

Need other small game source code or Python and crawler learning materials, you can add skirt 821189983, remarks S can be received, there are big god in the group oh.