Diff of /features/rgb_gr.py [000000] .. [f77492]

Switch to unified view

a b/features/rgb_gr.py
1
import os
2
import cv2
3
4
# data_path = 'test/'
5
# out_path = 'res/'
6
# filelist = os.listdir(data_path)
7
8
def trans(img):
9
    ht = img.shape[0]
10
    wd = img.shape[1]
11
    for i in range(0,ht):
12
        for j in range(0,wd):
13
            B = img[i][j][0]
14
            G = img[i][j][1]
15
            R = img[i][j][2]
16
            if B <= 51:
17
                img[i][j][0] = 255
18
            elif B <= 102:
19
                img[i][j][0] = 255 - (B-51)*5
20
            elif B <= 153:
21
                img[i][j][0] = 0
22
            else : img[i][j][0] = 0
23
24
            if G <= 51:
25
                img[i][j][1] = G*5
26
            elif G <= 102:
27
                img[i][j][1] = 255
28
            elif G <= 153:
29
                img[i][j][1] = 255
30
            elif G <= 204:
31
                img[i][j][1] = 255 - int(128.0*(G-153.0)/51.0 + 0.5)
32
            else : img[i][j][1] = 127 - int(127.0*(G-204.0)/51.0 + 0.5)
33
34
            if R <= 51:
35
                img[i][j][2] = 0
36
            elif R <= 102:
37
                img[i][j][2] = 0
38
            elif R <= 153:
39
                img[i][j][2] = (R-102)*5
40
            elif G <= 204:
41
                img[i][j][2] = 255
42
            else : img[i][j][2] = 255
43
    # cv2.imwrite(os.path.join(out_path,file_name),img)
44
    return img
45
46
47
# for onefile in filelist:
48
#     img = cv2.imread(data_path + onefile)
49
#     trans(onefile, img)