-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocess_mura.py
More file actions
62 lines (47 loc) · 2.03 KB
/
Copy pathpreprocess_mura.py
File metadata and controls
62 lines (47 loc) · 2.03 KB
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
# In[2]:
import os
from pathlib import Path
import shutil
target_dir = Path("/home/kailiang_fu/BoneyBoney/whole_dataset/train")
for body_part in ["ELBOW", "FINGER", "FOREARM", "HAND", "HUMERUS"]:
body_part_dir = target_dir.joinpath(Path(body_part))
os.mkdir(body_part_dir)
train_dir = Path('/home/kailiang_fu/MURA-v1.1/train/XR_' + body_part)
counter = 0
for sub_dir in os.listdir(train_dir):
sub_dir = train_dir.joinpath(sub_dir)
for study_dir in os.listdir(sub_dir):
study_dir = Path(sub_dir).joinpath(study_dir)
try:
for file_name in os.listdir(study_dir):
assert file_name.endswith('png')
src_file_path = study_dir.joinpath(file_name)
new_file_name = f"{counter}.png"
image_dst = body_part_dir.joinpath(Path(f"{counter}.png"))
shutil.copy(src_file_path, image_dst)
counter += 1
except NotADirectoryError:
pass
# In[3]:
target_dir = Path("/home/kailiang_fu/BoneyBoney/whole_dataset/test")
for body_part in ["ELBOW", "FINGER", "FOREARM", "HAND", "HUMERUS"]:
body_part_dir = target_dir.joinpath(Path(body_part))
os.mkdir(body_part_dir)
train_dir = Path('/home/kailiang_fu/MURA-v1.1/valid/XR_'+ body_part)
counter = 0
for sub_dir in os.listdir(train_dir):
sub_dir = train_dir.joinpath(sub_dir)
for study_dir in os.listdir(sub_dir):
study_dir = Path(sub_dir).joinpath(study_dir)
try:
for file_name in os.listdir(study_dir):
assert file_name.endswith('png')
src_file_path = study_dir.joinpath(file_name)
new_file_name = f"{counter}.png"
image_dst = body_part_dir.joinpath(Path(f"{counter}.png"))
shutil.copy(src_file_path, image_dst)
counter += 1
except NotADirectoryError:
pass