-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrealce.py
118 lines (73 loc) · 2.3 KB
/
realce.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import cv2
import numpy
def negativo(img):
rows, cols = img.shape
result = img.copy()
for i in range(rows):
for j in range(cols):
result[i, j] = 255 - img[i, j]
return result
def constraste(img, a, b, c, d):
rows, cols = img.shape
result = img.copy()
for i in range(rows):
for j in range(cols):
result[i, j] = (img[i, j] - a) * ((d - c) / (b - a)) + c
return result
def gama(img, y):
rows, cols = img.shape
result = numpy.zeros(rows * cols, dtype=numpy.float32).reshape((rows, cols))
c = 1
for i in range(rows):
for j in range(cols):
result[i,j] = c * numpy.power(img[i, j], y)
return numpy.uint8(result)
def linear(img, g, d):
rows, cols = img.shape
result = numpy.zeros(rows * cols, dtype=numpy.float32).reshape((rows, cols))
for i in range(rows):
for j in range(cols):
result[i, j] = g * img[i, j] + d
return numpy.uint8(result)
def logaritmo(img):
rows, cols = img.shape
result = numpy.zeros(rows * cols, dtype=numpy.float32).reshape((rows, cols))
g = 105.96
for i in range(rows):
for j in range(cols):
result[i, j] = g * numpy.log10(img[i, j] + 1)
return numpy.uint8(result)
def quadratic(img):
rows, cols = img.shape
result = numpy.zeros(rows * cols, dtype=numpy.float32).reshape((rows, cols))
g = 1 / 255
for i in range(rows):
for j in range(cols):
result[i, j] = g * numpy.power(img[i, j], 2)
return numpy.uint8(result)
def raiz(img):
rows, cols = img.shape
result = numpy.zeros(rows * cols, dtype=numpy.float32).reshape((rows, cols))
g = 255 / numpy.sqrt(255)
for i in range(rows):
for j in range(cols):
result[i, j] = g * numpy.sqrt(img[i, j])
return numpy.uint8(result)
img = cv2.imread("lena.jpg", 0)
neg = negativo(img.copy())
con = constraste(img.copy(), 0, 255, 0, 255)
gam = gama(img.copy(), 2)
lin = linear(img.copy(), 1, 32)
log = logaritmo(img.copy())
qua = quadratic(img.copy())
raiz = raiz(img.copy())
cv2.imshow("Original", img)
cv2.imshow("Negativo", neg)
cv2.imshow("Constraste", con)
cv2.imshow("Gama", gam)
cv2.imshow("Linear", lin)
cv2.imshow("Logaritmo", log)
cv2.imshow("Quadratico", qua)
cv2.imshow("Raiz", raiz)
cv2.waitKey(0)
cv2.destroyAllWindows()