/
rotate.py
executable file
·42 lines (33 loc) · 1.1 KB
/
rotate.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
#!/usr/bin/env python
# coding: utf-8
import os
import numpy as np
import argparse
from preprocess import rotate
from utils import for_each_sample, isCancerSample
# Globals
rotated_num = 0
def handle_sample(sample, patient, patientDir):
global rotated_num
if isCancerSample(sample) and not "R" in sample:
print("Rotating: {} {}".format(patient, sample))
rotated_num += 1
sampleArray = np.load(os.path.join(patientDir, sample))
for deg in [90, 180, 270]:
rotated = rotate(sampleArray, deg)
fileName = "R{}-".format(deg).join(sample.split("-"))
np.save(os.path.join(patientDir, fileName), rotated)
def main():
parser = argparse.ArgumentParser(description="Rotate images.")
parser.add_argument(
"relativePath",
type=str,
default=os.path.join("data", "preprocessed"),
nargs="?",
help="Relative path to proprocessed data",
)
args = parser.parse_args()
for_each_sample(args.relativePath, handle_sample)
print("Rotated: {}".format(rotated_num))
if __name__ == "__main__":
main()