|
a |
|
b/code/augmentation.py |
|
|
1 |
""" |
|
|
2 |
A utility script for data augmentation |
|
|
3 |
|
|
|
4 |
Usage: assign your path string to global variable 'path' |
|
|
5 |
""" |
|
|
6 |
|
|
|
7 |
import SimpleITK as sitk |
|
|
8 |
import numpy as np |
|
|
9 |
import csv |
|
|
10 |
from glob import glob |
|
|
11 |
import pandas as pd |
|
|
12 |
import os |
|
|
13 |
import matplotlib |
|
|
14 |
import matplotlib.pyplot as plt |
|
|
15 |
import traceback |
|
|
16 |
import random |
|
|
17 |
from PIL import Image |
|
|
18 |
|
|
|
19 |
path = '/home/ubuntu/data/train-3d/' |
|
|
20 |
|
|
|
21 |
file_list=glob(path+"*true*") |
|
|
22 |
for file in file_list: |
|
|
23 |
e = np.load(file) |
|
|
24 |
file_name = file.split('/')[-1] |
|
|
25 |
# several flip and rotation cases |
|
|
26 |
np.save(path+'1_'+file_name,np.transpose(e,(0,2,1))) |
|
|
27 |
np.save(path+'2_'+file_name,np.flipud(e)) |
|
|
28 |
np.save(path+'3_'+file_name,np.flipud(np.transpose(e,(0,2,1)))) |
|
|
29 |
np.save(path+'4_'+file_name,np.fliplr(e)) |
|
|
30 |
np.save(path+'5_'+file_name,np.transpose(np.fliplr(e),(0,2,1))) |
|
|
31 |
np.save(path+'6_'+file_name,np.flipud(np.fliplr(e))) |
|
|
32 |
np.save(path+'7_'+file_name,np.flipud(np.transpose(np.fliplr(e),(0,2,1)))) |
|
|
33 |
np.save(path+'8_'+file_name,np.transpose(np.rot90(e,1,(1,2)),(0,2,1))) |
|
|
34 |
np.save(path+'9_'+file_name,np.rot90(e,1,(1,2))) |
|
|
35 |
np.save(path+'10_'+file_name,np.flipud(np.transpose(np.rot90(e,1,(1,2)),(0,2,1)))) |
|
|
36 |
np.save(path+'11_'+file_name,np.flipud(np.rot90(e,1,(1,2)))) |
|
|
37 |
|