-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimage-brightness.py
72 lines (50 loc) · 1.47 KB
/
image-brightness.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
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
65
66
67
68
69
70
71
72
import sys
import time
import numpy as np
import cv2
def saturated(sum_value):
if sum_value > 255:
sum_value = 255
if sum_value < 0:
sum_value = 0
return sum_value
def main(argv):
filename = "../lena.png"
img_codec = cv2.IMREAD_COLOR
src = cv2.imread(filename, img_codec)
cv2.imshow("input", src)
src_shape = src.shape
print src_shape
dst = np.zeros(src.shape, src.dtype)
alpha = 2.0
beta = 0.0
for i in range(0, src_shape[0]):
for j in range(0, src_shape[1]):
for k in range(0, 3):
dst[i][j][k] = saturated(src[i][j][k] * alpha + beta)
print dst
cv2.imshow("output", dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
return 0
'''
cv2.imshow("Input", src)
t = round(time.time())
dst0 = sharpen(src)
t = (time.time() - t) / 1000
print("Hand written function time passed in seconds: %s" % t)
cv2.imshow("Output1", dst0)
cv2.waitKey()
t = time.time()
kernel = np.array([[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]], np.float32) # kernel should be floating point type
dst1 = cv2.filter2D(src, -1, kernel)
# ddepth = -1, means destination image has depth same as input image
t = (time.time() - t) / 1000
print("Built-in filter2D time passed in seconds: %s" % t)
cv2.imshow("Output2", dst1)
cv2.waitKey(0)
'''
if __name__ == "__main__":
main(sys.argv[1:])