-
Notifications
You must be signed in to change notification settings - Fork 10
/
data_v2.py
62 lines (43 loc) · 1.56 KB
/
data_v2.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
#!/usr/bin/env python
# coding=utf-8
#Author: Perfe
#E-mail: [email protected]
from __future__ import print_function
import os
import numpy as np
import cv2
import glob
img_rows = 420
img_cols = 580
def create_train_data():
train_data_path = glob.glob("../../train/*[0-9].tif")
# train_mask_path = glob.glob("../../train/1_*mask.tif")
train_data_path = np.array(train_data_path)
np.save("./generated_data/train_data_list.npy",train_data_path)
total = len(train_data_path)
train_images = np.ndarray((total,1,img_rows,img_cols),dtype=np.uint8)
train_class = np.ndarray((total,1),dtype=np.uint8)
print("-"*38)
print("Creating training images...")
print("-"*30)
for i,image_path in enumerate(train_data_path):
mask_path = image_path[:-4] + "_mask.tif"
image = cv2.imread(image_path,cv2.CV_LOAD_IMAGE_GRAYSCALE)
mask = cv2.imread(mask_path,cv2.CV_LOAD_IMAGE_GRAYSCALE)
image = np.array([image])
mask = np.array([mask])
if len(np.where(mask==255)[0]) > 500:
mask_class = 1
else:
mask_class = 0
train_images[i] = image
train_class[i] = mask_class
if i % 100 == 0:
print('Done:{0}/{1} images'.format(i,total))
print("Loading Done.")
print("train data's shape: ",train_images.shape)
np.save('./generated_data/train_images_v2.npy',train_images)
np.save('./generated_data/train_class_v2.npy',train_class)
print("train data saved.")
if __name__ == '__main__':
create_train_data()