Advertisement
collinsanele

Image2sketch py

Oct 1st, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import numpy as np
  2. import imageio
  3. import scipy.ndimage
  4. import cv2
  5.  
  6. img="photo.jpg"
  7.  
  8. def grayscale(rgb):
  9.     return np.dot(rgb[...,:3],[0.299,0.587,0.114])
  10.  
  11. def dodge(front,back):
  12.     result=front*255/(255-back)
  13.     result[result>255]=255
  14.     result[back==255]=255
  15.     return result.astype('uint8')
  16.  
  17.  
  18.  
  19. s=imageio.imread(img)
  20. g=grayscale(s)
  21. i=255-g
  22.  
  23. b=scipy.ndimage.filters.gaussian_filter(i,sigma=10)
  24. r=dodge(b,g)
  25.  
  26. cv2.imwrite('1.png',r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement