Advertisement
calfred2808

Image to sketch Python

Jul 11th, 2020
1,693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. #import the libraries
  2. import numpy as np
  3. import imageio
  4. import scipy.ndimage
  5. import cv2
  6.  
  7. #lets create a variable which will store a image
  8. img="my.jpg"
  9.  
  10. def grayscale(rgb):
  11.      return np.dot(rgb[...,:3],[0.299,0.587,0.114]) #this is the formuleto convert an image to black and white image
  12.  
  13. #this function will convert your image into sketch formate
  14.  def dodge(front,back):
  15.     result=front*255/(255-back)
  16.     result[result>255]=255
  17.     result[result==255]=255
  18.     return result.astype('uint8')
  19.    
  20. s=imageio.imread("my.jpg")
  21. g=grayscale(s)
  22. i=255-g
  23.  
  24. #lets create blurred image
  25. b=scipy.ndimage.filters.gaussian_filter(i,sigma=10)
  26. r=dodge(b,g)
  27.  
  28. #write the name of the picture which you have to want
  29. cv2.imwrite("my_sketch.png",r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement