forked from ke-22/deeplabv3-Tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_utils.py
38 lines (27 loc) · 1.02 KB
/
color_utils.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
import numpy as np
import cv2
# 给标签图上色
def color_predicts(img):
'''
给class图上色
'''
# img = cv2.imread(label_path,cv2.CAP_MODE_GRAY)
color = np.ones([img.shape[0], img.shape[1], 3])
color[img==0] = [255, 255, 255] #其他,白色,0
color[img==1] = [0, 255, 0] #植被,绿色,1
color[img==2] = [0, 0, 0] #道路,黑色,2
color[img==3] = [131, 139, 139] #建筑,黄色,3
color[img==4] = [139, 69, 19] #水体,蓝色,4
return color
def color_annotation(label_path, output_path):
'''
给class图上色
'''
img = cv2.imread(label_path,cv2.CAP_MODE_GRAY)
color = np.ones([img.shape[0], img.shape[1], 3])
color[img==0] = [255, 255, 255] #其他,白色,0
color[img==1] = [0, 255, 0] #植被,绿色,1
color[img==2] = [0, 0, 0] #道路,黑色,2
color[img==3] = [131, 139, 139] #建筑,黄色,3
color[img==4] = [139, 69, 19] #水体,蓝色,4
cv2.imwrite(output_path,color)