-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_list.py
49 lines (46 loc) · 1.69 KB
/
make_list.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
import os
from PIL import Image
import numpy as np
image_path_train = '/data4/chezhihao/remote_seg_data/WHU Dataset/train/image/'
image_path_val = '/data4/chezhihao/remote_seg_data/WHU Dataset/val/image/'
save_image_path = '/data4/chezhihao/remote_seg_data/WHU Dataset/VOC2007/JPEGImages/'
save_label_parh = '/data4/chezhihao/remote_seg_data/WHU Dataset/VOC2007/SegmentationClass/'
count = 0
print('--------train part--------')
for img in os.listdir(image_path_train):
img_path = image_path_train + img
label_path = img_path.replace('image', 'label')
image = Image.open(img_path)
label = Image.open(label_path).convert('L')
label = np.array(label)
for i in range(label.shape[0]):
for j in range(label.shape[1]):
if label[i][j] == 255:
label[i][j] = 1
save_path = save_image_path + str(count) + '.jpg'
image.save(save_path)
print(save_path)
save_path = save_label_parh + str(count) + '.png'
label = Image.fromarray(label)
label.save(save_path)
print(save_path)
count += 1
print('--------val part--------')
for img in os.listdir(image_path_val):
img_path = image_path_val + img
label_path = img_path.replace('image', 'label')
image = Image.open(img_path)
label = Image.open(label_path).convert('L')
label = np.array(label)
for i in range(label.shape[0]):
for j in range(label.shape[1]):
if label[i][j] == 255:
label[i][j] = 1
save_path = save_image_path + str(count) + '.jpg'
image.save(save_path)
print(save_path)
save_path = save_label_parh + str(count) + '.png'
label = Image.fromarray(label)
label.save(save_path)
print(save_path)
count += 1