-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch_filter.py
More file actions
64 lines (43 loc) · 1.89 KB
/
sketch_filter.py
File metadata and controls
64 lines (43 loc) · 1.89 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# import cv2
# import numpy as np
# # load the image to cartoonize
# img = cv2.imread("images/girl.png")
# # convert the image to grayscale
# img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# # apply median blur to remove niose
# img_gray = cv2.medianBlur(img_gray,5) #! how is used the kernel size in this function
# # extract the edges with Laplacian #! why
# # the countour of the figures inside the image
# edges = cv2.Laplacian(img_gray, cv2.CV_8U, ksize=5)
# # thresholding the edges
# #? this function take a pixel or color it the value is below the threshold the it will set it's value to black
# #? if the value is above the threshold the the color is set to white
# _, thresholded = cv2.threshold(edges,70,255,cv2.THRESH_BINARY_INV)
# # get the color with the bilateral filter
# color_img = cv2.bilateralFilter(img,10,250,250) # img, kernel , sigma_x , sigma_y, this function use a
# # gaussian distribution
# # merge color and edges
# skt = cv2.cvtColor(thresholded, cv2.COLOR_GRAY2BGR)
# sketch_img = cv2.bitwise_and(color_img, skt)
# cv2.namedWindow("Image", cv2.WINDOW_KEEPRATIO)
# cv2.imshow("Image",sketch_img)
import cv2
import numpy as np
#load the image to CARTOONIZE
img = cv2.imread("images/girl.png")
# convert the image to grayscale
img_gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# apply median blur to remove noise
img_gray= cv2.medianBlur(img_gray,5)
#extract the edges with Laplacian
edges= cv2.Laplacian(img_gray,cv2.CV_8U, ksize=5)
# thresholding the edges
_, thresholded= cv2.threshold(edges,70,255, cv2.THRESH_BINARY_INV)
#get the colors with the bilateral filter
color_img= cv2.bilateralFilter(img, 10,250,250)
#merge color and edges
skt= cv2.cvtColor(thresholded,cv2.COLOR_GRAY2BGR)
sketch_img= cv2.bitwise_and(color_img,skt)
cv2.namedWindow('img', cv2.WINDOW_KEEPRATIO)
cv2.imshow('img', sketch_img)
cv2.waitKey(0)