Convert Image To Sketch Using Python
Before you move forward don't forget to follow us on Instagram: @python.quest
Instructions:
1. Before you run this code make sure you have installed the following libraries:
a) imageio
b) scipy
c) openCV
2. Make sure you have the following Elon musk image with the name elon.jpg in your program folder.
3. You are free to copy-paste
this code now:
import numpy as np
import imageio
import scipy.ndimage
import cv2
img = "elon.jpg"
def rgb2gray(rgb):
return np.dot(rgb[..., :3], [0.2989, 0.5870, .1140])
def dodge(front,back):
final_sketch = front*255/(255-back)
final_sketch[final_sketch >255] =255
final_sketch[back == 255] =255
return final_sketch.astype('uint8')
ss = imageio.imread(img)
gray = rgb2gray(ss)
i = 255-gray
blur = scipy.ndimage.filters.gaussian_filter(i, sigma=13)
r = dodge(blur, gray)
cv2.imwrite('elon.png',r)
Output:
Comments
Post a Comment