-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_image.py
41 lines (24 loc) · 1.2 KB
/
merge_image.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
import os
import shutil
import glob
TRAIN_PATH = "./dataset/train/"
TEST_PATH = "./dataset/test/"
TRAIN_IMAGE_PATH = "./dataset/train_images/"
TRAIN_MASK_PATH = "./dataset/train_masks/"
TEST_IMAGE_PATH = "./dataset/test_images"
TEST_MASK_PATH = "./dataset/test_masks"
train_images = glob.glob(TRAIN_PATH + '/**/slice/*.tif', recursive=True)
train_masks = glob.glob(TRAIN_PATH + '/**/bone/*.tif', recursive=True)
test_images = glob.glob(TEST_PATH + '/**/slice/*.tif', recursive=True)
test_masks = glob.glob(TEST_PATH + '/**/bone/*.tif', recursive=True)
def copy(src, dest):
for idx, file_name_src in enumerate(src):
case_name = os.path.basename(os.path.dirname((os.path.dirname(file_name_src)))) # Would be "Subfolder_with_patientID1"
file_name = os.path.basename(file_name_src) # Would be "2.dcm"
file_name_dst = os.path.join(dest, f"{case_name}_{file_name}")
shutil.copy2(file_name_src, file_name_dst)
print(f"Copied:\n\tFr: {file_name_src}\n\tTo: {file_name_dst}")
src_list = [train_images, train_masks, test_images, test_masks]
dest_list = [TRAIN_IMAGE_PATH, TRAIN_MASK_PATH,TEST_IMAGE_PATH,TEST_MASK_PATH]
for i in range(4):
copy(src_list[i], dest_list[i])