-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_dataset.py
45 lines (41 loc) · 1.18 KB
/
generate_dataset.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
from __future__ import print_function
import matplotlib.pyplot as plt
import SimpleITK as sitk
import numpy as np
import sys, os
import png
import cv2
import shutil
cwd = os.getcwd()
Acount = 0
Bcount = 0
directory = os.path.join(cwd,'datasets','prostate')
testPathA = os.path.join(directory,'testA')
testPathB = os.path.join(directory,'testB')
trainPathA = os.path.join(directory,'trainA')
trainPathB = os.path.join(directory,'trainB')
if not os.path.exists(directory):
os.makedirs(testPathA)
os.makedirs(testPathB)
os.makedirs(trainPathA)
os.makedirs(trainPathB)
pathA = os.path.join(cwd,'T2')
pathB = os.path.join(cwd,'ADC')
for file in os.listdir(pathA):
file_path = os.path.join(pathA,file)
n = np.random.rand(1)
if int(file[11:14]) <= 300:
shutil.copy(file_path,trainPathA)
else:
shutil.copy(file_path,testPathA)
Acount += 1
print(Acount)
for file in os.listdir(pathB):
file_path = os.path.join(pathB,file)
n = np.random.rand(1)
if int(file[11:14]) <= 300:
shutil.copy(file_path,trainPathB)
else:
shutil.copy(file_path,testPathB)
Bcount += 1
print(Bcount)