-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
60 lines (49 loc) · 1.74 KB
/
Copy pathindex.py
File metadata and controls
60 lines (49 loc) · 1.74 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
import cv2
import numpy as np
#B1: Convert image to gray scale
img_rgb = cv2.imread("goku.png")
cv2.imshow("img_rgb", img_rgb)
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
cv2.imshow("img_gray", img_gray)
cv2.imwrite('img_gray.png',img_gray)
#B2: Obtain a negative
img_gray_inv=255-img_gray
#B3: Apply gausian blur #Effective way to reduce noise and reduce amount of detail in a image
img_blur = cv2.GaussianBlur(img_gray_inv, ksize=(21, 21),sigmaX=0, sigmaY=0)
cv2.imshow("img_blur", img_blur)
cv2.imwrite('img_blur.png',img_blur)
#B4: Blend the grayscale image with the blurred negative
def dodgeNaive(image, mask):
# determine the shape of the input image
width,height = image.shape [:2]
# prepare output argument with same size as image
blend = np.zeros((width,height), np.uint8)
for col in xrange(width):
for row in xrange(height):
# do for every pixel
if mask[c,r] == 255:
# avoid division by zero
blend[c,r] = 255
else:
# shift image pixel value by 8 bits
# divide by the inverse of the mask
tmp = (image[c,r] << 8) / (255-mask)
# make sure resulting value stays within bounds
if tmp > 255:
tmp = 255
blend[c,r] = tmp
return blend
def dodgeV2(image, mask):
return cv2.divide(image, 255-mask, scale=256)
def dodge(front,back):
result=front*255/(255-back)
result[np.logical_or(result > 255, back ==255)] =255
return result.astype('uint8')
'''
def burnV2(image, mask):
return 255–cv2.divide(255-image, 255-mask, scale=256)
'''
img_blend = dodgeV2(img_gray, img_blur)
cv2.imshow("pencil sketch", img_blend)
cv2.imwrite('pencil_sketch.png',img_blend)
cv2.waitKey(0)