-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathACWS_TransposeOrientations.py
More file actions
49 lines (44 loc) · 1.69 KB
/
ACWS_TransposeOrientations.py
File metadata and controls
49 lines (44 loc) · 1.69 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 21 11:57:33 2022
@author: smith
"""
import os
import numpy as np
from skimage import io
import argparse
def horizontalToCoronal(img_path):
f, e = os.path.splitext(img_path)
if f.endswith('.ome'):
f = f.strip('.ome')
save_path = f+'_Coronal.tif'
im = io.imread(img_path)
print("Image loaded with size " + str(im.shape))
im_corr = im.transpose(1,2,0)
io.imsave(save_path, im_corr, check_contrast=False)
def horizontalToSagittal(img_path):
f, e = os.path.splitext(img_path)
if f.endswith('.ome'):
f = f.strip('.ome')
save_path = f+'_Sagittal.tif'
im = io.imread(img_path)
print("Image loaded with size " + str(im.shape))
im_sag = im.transpose(2,0,1)
io.imsave(save_path, im_sag, check_contrast=False)
if __name__ == '__main__':
p = argparse.ArgumentParser()
p.add_argument('-i', '--img_path',type=str,default=None,help='Full path to image for resampling')
p.add_argument('-s', '--source',type=str,default='horizontal',help='Orientation of source image; default horizontal.')
p.add_argument('-t', '--target',type=str,default='coronal',help='Target orientation. Default coronal.')
args = p.parse_args()
args.source = args.source.lower()
args.target = args.target.lower()
if args.img_path==None:
raise NameError("img_path argument must be full path to image")
if not args.source=='horizontal':
raise NameError("Sorry, at this time this script only supports horizontal source images")
if args.target=='coronal':
horizontalToCoronal(args.img_path)
elif args.target=='sagittal':
horizontalToSagittal(args.img_path)