-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathXT_subtract_channel.py
90 lines (67 loc) · 2.92 KB
/
XT_subtract_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
# Subtracting Channels
#
# Copyright (C) 2018 Nilesh Patil <[email protected]>, MIT license
#
# <CustomTools>
# <Menu name = "Python plugins">
# <Submenu name = "Channel Mods">
# <Item name="Subtract Channel" icon="Python" tooltip="Subtract One Channel from Another">
# <Command>PythonXT::XT_subtract_channel(%i)</Command>
# </Item>
# </Submenu>
# </Menu>
# </CustomTools>
import time
import ImarisLib
import BridgeLib
import numpy as np
from cvbi.gui import create_window_from_list
from tqdm import tqdm
from sklearn.cluster import KMeans
# Get Clusters at every time point
def XT_subtract_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(channel_list, 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(channel_list, 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)
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)
data_out = data_channel_01-data_channel_02
data_out[data_out<0] = 0
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)