-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathXT_combine_channel.py
103 lines (79 loc) · 3.71 KB
/
XT_combine_channel.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
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
100
101
102
103
# Subtracting Channels
#
# Copyright (C) 2018 Nilesh Patil <[email protected]>, MIT license
#
# <CustomTools>
# <Menu name = "Python plugins">
# <Submenu name = "Channel Mods">
# <Item name="Combine Channels" icon="Python" tooltip="Combine channels by a mathematical operation">
# <Command>PythonXT::XT_combine_channel(%i)</Command>
# </Item>
# </Submenu>
# </Menu>
# </CustomTools>
import time
import ImarisLib
import numpy as np
from cvbi.gui import *
from tqdm import tqdm
# Get Clusters at every time point
def XT_combine_channel(aImarisId):
vImarisLib = ImarisLib.ImarisLib()
vImaris = vImarisLib.GetApplication(aImarisId)
vDataSet = vImaris.GetDataSet()
print('''
####################################################################################
########################### Extension started ##############################
####################################################################################
''')
time.sleep(2)
nC = vDataSet.GetSizeC()
nT = vDataSet.GetSizeT()
channel_list = range(1, nC+1)
channel_selected_01 = create_window_from_list(object_list=channel_list,
w=400, h=len(channel_list)*45,
window_title='Select channel A')
ch_in_01 = np.int64(channel_selected_01)
ch_in_01_name = vDataSet.GetChannelName(ch_in_01-1)
print('Input acquired for channel : '+str(ch_in_01_name))
time.sleep(2)
channel_selected_02 = create_window_from_list(object_list=channel_list,
w=400, h=len(channel_list)*45,
window_title='Select channel B')
ch_in_02 = np.int64(channel_selected_02)
ch_in_02_name = vDataSet.GetChannelName(ch_in_02-1)
print('Input acquired for channel : '+str(ch_in_02_name))
time.sleep(2)
operation_list = ['add', 'subtract', 'multiply']
operation_selected = create_window_from_list(object_list=operation_list,
w=400, h=len(operation_list)*45,
window_title='Select Operation')
print('Selected operation : '+operation_selected)
time.sleep(2)
ch_out = nC+1
ch_out_name = 'Channel '+str(ch_in_01) + '-' + ' Channel '+str(ch_in_02)
vDataSet.SetSizeC(ch_out)
vDataSet.SetChannelName(ch_out - 1, ch_out_name)
print('Selected Channels are : '+str(ch_in_01_name)+' and '+str(ch_in_02_name))
time.sleep(5)
print('\n\n Calculating difference between channels : \n\n')
for ti in tqdm(range(nT)):
data_channel_list_01 = vDataSet.GetDataVolumeFloats(aIndexC=ch_in_01-1, aIndexT=ti)
data_channel_01 = np.array(data_channel_list_01)
data_channel_list_02 = vDataSet.GetDataVolumeFloats(aIndexC=ch_in_02-1, aIndexT=ti)
data_channel_02 = np.array(data_channel_list_02)
if operation_selected == 'add':
data_out = data_channel_01 + data_channel_02
if operation_selected == 'subtract':
data_out = data_channel_01 - data_channel_02
if operation_selected == 'multiply':
data_out = data_channel_01 * data_channel_02
data_out_list = data_out.tolist()
vDataSet.SetDataVolumeFloats(aData=data_out_list, aIndexC=ch_out-1, aIndexT=ti)
time.sleep(3)
print('''
####################################################################################
######### Extension finished, wait for 5s to close automatically ###########
####################################################################################
''')
time.sleep(5)