[cf6a9e]: / features / rgb_gr.py

Download this file

49 lines (43 with data), 1.3 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
import os
import cv2
# data_path = 'test/'
# out_path = 'res/'
# filelist = os.listdir(data_path)
def trans(img):
ht = img.shape[0]
wd = img.shape[1]
for i in range(0,ht):
for j in range(0,wd):
B = img[i][j][0]
G = img[i][j][1]
R = img[i][j][2]
if B <= 51:
img[i][j][0] = 255
elif B <= 102:
img[i][j][0] = 255 - (B-51)*5
elif B <= 153:
img[i][j][0] = 0
else : img[i][j][0] = 0
if G <= 51:
img[i][j][1] = G*5
elif G <= 102:
img[i][j][1] = 255
elif G <= 153:
img[i][j][1] = 255
elif G <= 204:
img[i][j][1] = 255 - int(128.0*(G-153.0)/51.0 + 0.5)
else : img[i][j][1] = 127 - int(127.0*(G-204.0)/51.0 + 0.5)
if R <= 51:
img[i][j][2] = 0
elif R <= 102:
img[i][j][2] = 0
elif R <= 153:
img[i][j][2] = (R-102)*5
elif G <= 204:
img[i][j][2] = 255
else : img[i][j][2] = 255
# cv2.imwrite(os.path.join(out_path,file_name),img)
return img
# for onefile in filelist:
# img = cv2.imread(data_path + onefile)
# trans(onefile, img)