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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 | def __init__(self, img_path:str, img_name:str,
ch_order:dict[str:int], use_gauss:bool=False, wf_sigma:float=.5, border_crop:int=0,
**kwargs):
""" Class is designed to store experiment data from wide-field imaging
using two different excitation wavelengths and two emission channels (__2 eXcitation & 2 eMission__).
It's specifically optimized for the results of individual neuron imaging.
Parameters
----------
img_path: str
path to the image series TIFF file
img_name: str
recording name
ch_order: dict
indexes of 1st and 2nd fluorescence proteins channels,
if fluorescence proteins doesn't overlap (`{'fp1': index, 'fp2': index}`)
use_gauss: boolean, optional
if `True` Gaussian filter will be applied to input image series
wf_sigma: float, optional
sigma value for Gaussian filter applied to input image series
border_crop: int (0)
image crop size in pixels,
this amount of pixels will be deleted from sides on each frame
Attributes
----------
img_raw: ndarray [t,x,y,c]
raw input image series
img_name: str
registration name
fp1_img: ndarray [t,x,y]
1st fluorescence protein image series
with photobleaching correction and Gaussian filtering (if `use_gauss` is `True`)
fp1_img_raw: ndarray [t,x,y]
1st fluorescence protein image series,
without photobleaching correction and Gaussian filtering
fp1_img_corr: ndarray [t,x,y]
1st fluorescence image series
with photobleaching correction
fp1_mean_img_raw: ndarray [x,y]
1st fluorescence protein pixel-wise mean image
fp2_img: ndarray [t,x,y]
2nd fluorescence protein image series,
with photobleaching correction and Gaussian filtering (if `use_gauss` is `True`)
fp2_img_raw: ndarray [t,x,y]
2nd fluorescence protein image series,
without photobleaching correction and Gaussian filtering
fp2_img_corr: ndarray [t,x,y]
2nd fluorescence protein image series
with photobleaching correction
fp2_mean_img_raw: ndarray [x,y]
2nd fluorescence protein pixel-wise mean image
proc_mask: ndarray [x,y]
cell processes boolean mask, extended (created with `utils.masking.proc_mask()`)
narrow_proc_mask: ndarray [x,y]
cell processes boolean mask, unextended (created with `utils.masking.proc_mask()`)
"""
self.img_raw = io.imread(img_path)
if border_crop !=0: # optional crop of image series
y,x = self.img_raw.shape[1:3]
self.img_raw = self.img_raw[:,border_crop:y-border_crop,border_crop:x-border_crop,:]
self.img_name = img_name
self.ch_order = ch_order
self.gauss_sigma = gauss_sigma
# primary image extraction
self.fp1_img_raw = self.img_raw[:,:,:,ch_order['fp1']]
self.fp2_img_raw = self.img_raw[:,:,:,ch_order['fp2']]
self.fp1_mean_img_raw = np.mean(self.fp1_img_raw, axis=0)
self.fp2_mean_img_raw = np.mean(self.fp2_img_raw, axis=0)
# mask creation
self.proc_mask = masking.proc_mask(self.fp2_mean_img_raw,
ext_fin_mask=True, **kwargs)
self.narrow_proc_mask = masking.proc_mask(self.fp2_mean_img_raw,
ext_fin_mask=False, **kwargs)
# photobleaching correction and bluring
self.fp1_img_corr,self.fb1_pbc,self.fb1_pb_r = masking.pb_exp_correction(input_img=self.fp1_img_raw,
mask=self.proc_mask)
self.fp1_back_mean = np.mean(self.fp1_img_corr, axis=(1,2), where=~self.proc_mask)
self.fp1_back_mean = self.fp1_back_mean.reshape(-1, 1, 1)
self.fp1_img_corr = self.fp1_img_corr - self.fp1_back_mean
self.fp2_img_corr,self.fb2_pbc,self.fb2_pb_r = masking.pb_exp_correction(input_img=self.fp2_img_raw,
mask=self.proc_mask)
self.fp2_back_mean = np.mean(self.fp2_img_corr, axis=(1,2), where=~self.proc_mask)
self.fp2_back_mean = self.fp2_back_mean.reshape(-1, 1, 1)
self.fp2_img_corr = self.fp2_img_corr - self.fp2_back_mean
if use_gauss:
self.fp1_img = np.asarray([filters.gaussian(frame, sigma=self.gauss_sigma) \
for frame in self.fp1_img_corr])
self.fp2_img = np.asarray([filters.gaussian(frame, sigma=self.gauss_sigma) \
for frame in self.fp2_img_corr])
else:
self.fp1_img = self.fp1_img_corr
self.fp2_img = self.fp2_img_corr
|