-
Notifications
You must be signed in to change notification settings - Fork 0
/
mask_deal.py
122 lines (114 loc) · 3.5 KB
/
mask_deal.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
119
120
121
122
import numpy as np
def encode_labels(color_mask):
encode_mask = np.zeros((color_mask.shape[0], color_mask.shape[1]))
# 0
encode_mask[color_mask == 0] = 0
encode_mask[color_mask == 249] = 0
encode_mask[color_mask == 255] = 0
# 1
encode_mask[color_mask == 200] = 1
encode_mask[color_mask == 204] = 1
encode_mask[color_mask == 213] = 0
encode_mask[color_mask == 209] = 1
encode_mask[color_mask == 206] = 0
encode_mask[color_mask == 207] = 0
# 2
encode_mask[color_mask == 201] = 2
encode_mask[color_mask == 203] = 2
encode_mask[color_mask == 211] = 0
encode_mask[color_mask == 208] = 0
# 3
encode_mask[color_mask == 216] = 0
encode_mask[color_mask == 217] = 3
encode_mask[color_mask == 215] = 0
# 4 In the test, it will be ignored
encode_mask[color_mask == 218] = 0
encode_mask[color_mask == 219] = 0
# 4
encode_mask[color_mask == 210] = 4
encode_mask[color_mask == 232] = 0
# 5
encode_mask[color_mask == 214] = 5
# 6
encode_mask[color_mask == 202] = 0
encode_mask[color_mask == 220] = 6
encode_mask[color_mask == 221] = 6
encode_mask[color_mask == 222] = 6
encode_mask[color_mask == 231] = 0
encode_mask[color_mask == 224] = 6
encode_mask[color_mask == 225] = 6
encode_mask[color_mask == 226] = 6
encode_mask[color_mask == 230] = 0
encode_mask[color_mask == 228] = 0
encode_mask[color_mask == 229] = 0
encode_mask[color_mask == 233] = 0
# 7
encode_mask[color_mask == 205] = 7
encode_mask[color_mask == 212] = 0
encode_mask[color_mask == 227] = 7
encode_mask[color_mask == 223] = 0
encode_mask[color_mask == 250] = 7
return encode_mask
def decode_labels(labels):
deocde_mask = np.zeros((labels.shape[0], labels.shape[1]), dtype='uint8')
# 0
deocde_mask[labels == 0] = 0
# 1
deocde_mask[labels == 1] = 204
# 2
deocde_mask[labels == 2] = 203
# 3
deocde_mask[labels == 3] = 217
# 4
deocde_mask[labels == 4] = 210
# 5
deocde_mask[labels == 5] = 214
# 6
deocde_mask[labels == 6] = 224
# 7
deocde_mask[labels == 7] = 227
return deocde_mask
def decode_color_labels(labels):
decode_mask = np.zeros((3, labels.shape[0], labels.shape[1]), dtype='uint8')
# 0
decode_mask[0][labels == 0] = 0
decode_mask[1][labels == 0] = 0
decode_mask[2][labels == 0] = 0
# 1
decode_mask[0][labels == 1] = 70
decode_mask[1][labels == 1] = 130
decode_mask[2][labels == 1] = 180
# 2
decode_mask[0][labels == 2] = 0
decode_mask[1][labels == 2] = 0
decode_mask[2][labels == 2] = 142
# 3
decode_mask[0][labels == 3] = 153
decode_mask[1][labels == 3] = 153
decode_mask[2][labels == 3] = 153
# 4
decode_mask[0][labels == 4] = 128
decode_mask[1][labels == 4] = 64
decode_mask[2][labels == 4] = 128
# 5
decode_mask[0][labels == 5] = 190
decode_mask[1][labels == 5] = 153
decode_mask[2][labels == 5] = 153
# 6
decode_mask[0][labels == 6] = 0
decode_mask[1][labels == 6] = 0
decode_mask[2][labels == 6] = 230
# 7
decode_mask[0][labels == 7] = 255
decode_mask[1][labels == 7] = 128
decode_mask[2][labels == 7] = 0
return decode_mask
def verify_labels(labels):
pixels = [0]
for x in range(labels.shape[0]):
for y in range(labels.shape[1]):
pixel = labels[x, y]
if pixel not in pixels:
pixels.append(pixel)
print('The Labels Has Value:', pixels)
return pixels