-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
28 lines (20 loc) · 881 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import cv2
import numpy as np
def dodge_v2(image, mask):
return cv2.divide(image, 255 - mask, scale=256)
def img2sketch(source_path, destination_path):
source_photo = cv2.imread(source_path)
scale_percent = 1
width = int(source_photo.shape[1] * scale_percent)
height = int(source_photo.shape[0] * scale_percent)
dim = (width, height)
resized = cv2.resize(source_photo, dim, interpolation=cv2.INTER_AREA)
kernel_sharpening = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]])
sharpened = cv2.filter2D(resized, -1, kernel_sharpening)
gray = cv2.cvtColor(sharpened, cv2.COLOR_BGR2GRAY)
inv = 255 - gray
gauss = cv2.GaussianBlur(inv, ksize=(15, 15), sigmaX=0, sigmaY=0)
pencil_photo = dodge_v2(gray, gauss)
cv2.imwrite(destination_path, pencil_photo)
if __name__ == "__main__":
img2sketch("Luffy.jpg", "Luffy5.jpg")