-
Notifications
You must be signed in to change notification settings - Fork 12
/
Prepare_ph2.py
79 lines (56 loc) · 2.07 KB
/
Prepare_ph2.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
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 8 18:15:43 2019
@author: Reza Azad
"""
from __future__ import division
import numpy as np
import scipy.io as sio
import scipy.misc as sc
import glob
import random
#from sklearn.model_selection import train_test_split
# Parameters
height = 256
width = 256
channels = 3
############################################################# Prepare ph2 data set #################################################
Dataset_add = 'data/'
Tr_add = 'lesions/'
Tr_list = glob.glob(Dataset_add+ Tr_add+'/*.bmp')
# It contains 2594 training samples
Data_train = np.zeros([200, height, width, channels])
Label_train = np.zeros([200, height, width])
print('Reading Ph2')
random.shuffle(Tr_list)
for idx in range(len(Tr_list)):
print(idx+1)
print(Tr_list[idx])
img = sc.imread(Tr_list[idx])
img = np.double(sc.imresize(img, [height, width, channels], interp='bilinear', mode = 'RGB'))
Data_train[idx, :,:,:] = img
b = Tr_list[idx]
#print(b)
a = b[0:len(Dataset_add)]
b = b[len(b)-10: len(b)-4]
# print(a)
# print(b)
add = (a+ 'masks/' + b +'_lesion.bmp')
img2 = sc.imread(add)
img2 = np.double(sc.imresize(img2, [height, width], interp='bilinear'))
Label_train[idx, :,:] = img2
print('Reading Ph2 finished')
################################################################ Make the train and test sets ########################################
# We consider 80 samples for training, 20 samples for validation and 100 samples for testing
Train_img = Data_train[0:80,:,:,:]
Validation_img = Data_train[80:100,:,:,:]
Test_img = Data_train[100:200,:,:,:]
Train_mask = Label_train[0:80,:,:]
Validation_mask = Label_train[80:100,:,:]
Test_mask = Label_train[100:200,:,:]
np.save('data_train', Train_img)
np.save('data_test' , Test_img)
np.save('data_val' , Validation_img)
np.save('mask_train', Train_mask)
np.save('mask_test' , Test_mask)
np.save('mask_val' , Validation_mask)