-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_gt2annotations_potsdam.py
72 lines (66 loc) · 3.15 KB
/
convert_gt2annotations_potsdam.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
import os
import numpy as np
from scipy import misc
from cv2 import imread, imwrite
ground_truth_path = "../ISPRS_semantic_labeling_Potsdam/5_Labels_for_participants"
annotaions_path = "../ISPRS_semantic_labeling_Potsdam/annotations"
for filename in os.listdir(ground_truth_path):
print(">> Processing", filename)
image = imread(os.path.join(ground_truth_path, filename))
annotation_image = np.zeros((np.shape(image)[0], np.shape(image)[1]))
for i in range(np.shape(image)[0]):
for j in range(np.shape(image)[1]):
if np.array_equal(image[i, j, :], np.array([255, 255, 255])):
# Impervious surfaces (RGB: 255, 255, 255)
annotation_image[i, j] = 0
elif np.array_equal(image[i,j,:],np.array([0, 0, 255])):
# Building (RGB: 0, 0, 255)
annotation_image[i, j] = 1
elif np.array_equal(image[i,j,:],np.array([0, 255, 255])):
# Low vegetation (RGB: 0, 255, 255)
annotation_image[i, j] = 2
elif np.array_equal(image[i,j,:],np.array([0, 255, 0])):
# Tree (RGB: 0, 255, 0)
annotation_image[i, j] = 3
elif np.array_equal(image[i,j,:],np.array([255, 255, 0])):
# Car (RGB: 255, 255, 0)
annotation_image[i, j] = 4
else:
# Clutter/background (RGB: 255, 0, 0)
# high = 5
annotation_image[i, j] = 5
annotation_filename = os.path.splitext(filename)[0]
imwrite(os.path.join(annotaions_path, annotation_filename + ".png"), annotation_image)
print('Done!')
""" import os
import numpy as np
from scipy import misc
ground_truth_path="ISPRS_semantic_labeling_Potsdam/5_Labels_for_participants"
annotaions_path="ISPRS_semantic_labeling_Potsdam/annotations"
high=4
for filename in os.listdir(ground_truth_path):
if '.tif' in filename:
image= misc.imread(os.path.join(ground_truth_path,filename))
annotation_image=np.zeros((np.shape(image)[0],np.shape(image)[1]))
for i in range(np.shape(image)[0]):
print(i)
for j in range(np.shape(image)[1]):
if np.array_equal(image[i,j,:],np.array([255,255,255])):
annotation_image[i,j]=0
elif np.array_equal(image[i,j,:],np.array([0,0,255])):
annotation_image[i, j] = 1
elif np.array_equal(image[i,j,:],np.array([0,255,255])):
annotation_image[i, j] = 2
elif np.array_equal(image[i,j,:],np.array([0,255,0])):
annotation_image[i, j] = 3
elif np.array_equal(image[i,j,:],np.array([255,255,0])):
annotation_image[i, j] = 4
else:
high=5
annotation_image[i,j]=5
annotation_filename= os.path.splitext(filename)[0]
print(np.shape(annotation_image))
#misc.imsave(os.path.join(annotaions_path,annotation_filename+".jpg"),annotation_image)
misc.toimage(annotation_image,high=high,low=0).save(os.path.join(annotaions_path,annotation_filename+".png"))
high=4
print("Done!") """