-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopySampleImages.py
More file actions
46 lines (34 loc) · 1.14 KB
/
CopySampleImages.py
File metadata and controls
46 lines (34 loc) · 1.14 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
#! /home/spl/ml/sitk/bin/python
import os
import shutil
import glob
import sys
from pathlib import Path
import re
if len(sys.argv) == 1:
masterdir = Path.cwd()
else:
masterdir = Path(sys.argv[1])
sampledir = os.path.join(masterdir,'sampleImg')
if not os.path.exists(sampledir):
os.mkdir(sampledir)
else:
shutil.rmtree(sampledir)
os.mkdir(sampledir)
failed = [] # use this one to output a list of failed registration
for folder in os.listdir(masterdir):
if 'tibia' in folder.lower(): #if 'week' in folder.lower():
images = [image for image in sorted(glob.glob(os.path.join(masterdir,folder,'*')))
if re.search(r"(00\d{3,6}).(tif|bmp|png)$",image)]
try:
distal=images[0] #420
midline = images[int(len(images)*0.7)]
proximal=images[-75]
sampleimg = [proximal,distal,midline]
for img in sampleimg:
shutil.copyfile(img,os.path.join(sampledir,os.path.basename(img)))
except IndexError:
print('No files for {}'.format(folder))
failed.append(folder) #
continue
print('Done!') #