forked from nilesh-patil/python-XTensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXT_get_fiber_angle_slice.py
More file actions
99 lines (80 loc) · 3.4 KB
/
XT_get_fiber_angle_slice.py
File metadata and controls
99 lines (80 loc) · 3.4 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Template Extension
#
# Copyright (C) 2018 Nilesh patil <nilesh.patil@rochester.edu>, MIT license
#
# <CustomTools>
# <Menu name = "Python plugins">
# <Submenu name = "Channel Mods">
# <Item name="Get Orientation at each voxel" icon="Python" tooltip="Description to be shown in tooltip">
# <Command>PythonXT::XT_get_fiber_angle(%i)</Command>
# </Item>
# </Submenu>
# </Menu>
# </CustomTools>
import time
# Template Extension description for function
import warnings
import numpy as np
from tqdm import tqdm
import ImarisLib
from cvbi.gui import *
from cvbi.image.orientation import get_image_angles
def XT_get_fiber_angle(aImarisId):
vImarisLib = ImarisLib.ImarisLib()
vImaris = vImarisLib.GetApplication(aImarisId)
vDataSet = vImaris.GetDataSet()
print('''
####################################################################################
########################### Extension started ##############################
####################################################################################
''')
time.sleep(2)
nX = vDataSet.GetSizeX()
nY = vDataSet.GetSizeY()
nZ = vDataSet.GetSizeZ()
nT = vDataSet.GetSizeT()
nC = vDataSet.GetSizeC()
# Select Channel
channel_list = range(1 , nC + 1)
channel_selected = create_window_from_list(channel_list , window_title = 'Select Channel')
ch_in = np.int64(channel_selected)
ch_in_name = vDataSet.GetChannelName(ch_in - 1)
print('Channel Selected : ' + ch_in_name)
time.sleep(2)
# Create Output Channel
ch_out = nC + 1
ch_out_name = 'Orientation calculated from Channel : ' + ch_in_name
vDataSet.SetSizeC(ch_out)
vDataSet.SetChannelName(ch_out - 1 , ch_out_name)
print('Channel Created : ' + ch_out_name)
time.sleep(2)
# Get other parameters
window_size = 13
window_overlap = 0.24
print('Starting with default parameters : '
'Window Size = {window_size}, '
'Overlap = {window_overlap}'.format(window_size = window_size , window_overlap = window_overlap))
time.sleep(2)
warnings.simplefilter("ignore")
for t in tqdm(np.arange(nT)):
for z in np.arange(nZ):
data_in = vDataSet.GetDataSliceFloats(aIndexZ = z , aIndexC = ch_in - 1 , aIndexT = t)
nearest_image = np.array(data_in).copy()
cutoff = np.percentile(nearest_image , 90)
# Create cutoff image
nearest_image_cutoff = nearest_image.copy()
nearest_image_cutoff[nearest_image_cutoff <= cutoff] = 0.0
angle_array , X , Y , U , V = get_image_angles(im = nearest_image_cutoff + 1e-6 ,
window_size = window_size ,
window_overlap = window_overlap)
angle_array = np.rad2deg(angle_array)
angle_array[np.isnan(angle_array)] = 0
data_out = angle_array.tolist()
vDataSet.SetDataSliceFloats(aData = data_out , aIndexZ = z , aIndexC = ch_out - 1 , aIndexT = t)
time.sleep(2)
print('''
####################################################################################
######### Extension finished, wait for 5s to close automatically ###########
####################################################################################
''')
time.sleep(5)