forked from vieiraeduardos/ufma-processing-image-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcores.py
77 lines (50 loc) · 1.75 KB
/
cores.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
import cv2
import numpy as np
def gray(img):
rows, cols, channels = img.shape
result = img.copy()
for i in range(rows):
for j in range(cols):
aux = 0
for k in range(channels):
aux += img[i, j, k]
result[i, j] = aux / 3
return result
def CMY(img):
rows, cols, channels = img.shape
result = img.copy()
for i in range(rows):
for j in range(cols):
for k in range(channels):
result[i, j, k] = 255 - img[i, j, k]
return result
def YCrCb(img):
rows, cols, channels = img.shape
result = img.copy()
for i in range(rows):
for j in range(cols):
result[i, j, 0] = (0.299*img[i, j, 2]) + (0.587*img[i, j, 1]) + (0.114*img[i, j, 0])
result[i, j, 1] = (img[i, j, 2]-((0.299*img[i, j, 2]) + (0.587*img[i, j, 1]) + (0.114*img[i, j, 0])))*0.713 + 128
result[i, j, 2] = (img[i, j, 0]-(0.299*img[i, j, 2]) + (0.587*img[i, j, 1]) + (0.114*img[i, j, 0]))*0.713 + 128
return result
def YUV(img):
rows, cols, channels = img.shape
result = img.copy()
for i in range(rows):
for j in range(cols):
result[i, j, 0] = (0.299*img[i, j, 2]) + (0.587*img[i, j, 1]) + (0.114*img[i, j, 0])
result[i, j, 1] = (img[i, j, 2]-((0.299*img[i, j, 2]) + (0.587*img[i, j, 1]) + (0.114*img[i, j, 0])))
result[i, j, 2] = (img[i, j, 0]-(0.299*img[i, j, 2]) + (0.587*img[i, j, 1]) + (0.114*img[i, j, 0]))
return result
img = cv2.imread("lena.jpg", 1)
gray = gray(img.copy())
cmy = CMY(img.copy())
ycrcb = YCrCb(img.copy())
yuv = YUV(img.copy())
cv2.imshow("Imagem", img)
cv2.imshow("Cinza", gray)
cv2.imshow("CMY", cmy)
cv2.imshow("YCrCb", ycrcb)
cv2.imshow("YUV", yuv)
cv2.waitKey(0)
cv2.destroyAllWindows()