-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset_mccad.py
42 lines (32 loc) · 1.27 KB
/
dataset_mccad.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
import scipy
import torch.utils.data
import numpy as np
import random
def CreateDatasetSynthesis(phase, input_path):
target_file = input_path + phase+"/t1.mat"
data_fs_s1=LoadDataSet(target_file)
target_file = input_path + phase+"/t2.mat"
data_fs_s2=LoadDataSet(target_file)
target_file = input_path + phase+"/flair.mat"
data_fs_s4=LoadDataSet(target_file)
dataset=torch.utils.data.TensorDataset( torch.from_numpy(data_fs_s1), torch.from_numpy(data_fs_s2), torch.from_numpy(data_fs_s4))
return dataset
#Dataset loading from load_dir and converintg to 256x256
def LoadDataSet(load_dir, variable = 'slices', padding = True, Norm = True):
f = scipy.io.loadmat(load_dir)
if np.array(f[variable]).ndim==3:
data=np.expand_dims(np.transpose(np.array(f[variable]),(0,2,1)),axis=1)
else:
data=np.transpose(np.array(f[variable]),(1,0,3,2))
if Norm:
data=data.astype(np.float32)
else:
data=data.astype(np.uint8)
if padding:
pad_x=int((256-data.shape[2])/2)
pad_y=int((256-data.shape[3])/2)
print('padding in x-y with:'+str(pad_x)+'-'+str(pad_y))
data=np.pad(data,((0,0),(0,0),(pad_x,pad_x),(pad_y,pad_y)))
if Norm:
data=(data-0.5)/0.5
return data