Wide field with 2 excitation wavelengths & 2 emission channels

wf_x2_m2

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[str:int]) –

    indexes of 1st and 2nd fluorescence proteins channels, if fluorescence proteins doesn't overlap ({'fp1': index, 'fp2': index})

  • use_gauss (bool, default: False ) –

    if True Gaussian filter will be applied to input image series

  • wf_sigma (float, default: 0.5 ) –

    sigma value for Gaussian filter applied to input image series

  • border_crop (int, default: 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())

Source code in src/domb/reg_type/wf_x2_m2.py
 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

ch_pic

Plotting of registration control image

src/domb/reg_type/wf_x2_m2.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def ch_pic(self):
    """ Plotting of registration control image

    """
    v_min = np.min(self.img_raw)
    v_max = np.max(self.img_raw) * .5

    fp1_der_w, fp1_der_p = masking.series_derivate(input_img=self.fp1_img_corr,
                                                   mask=self.proc_mask,
                                                   left_win=2, space=4, right_win=2)
    fp2_der_w, fp2_der_p = masking.series_derivate(input_img=self.fp2_img_corr,
                                                   mask=self.proc_mask,
                                                   left_win=2, space=4, right_win=2)

    plt.figure(figsize=(10,10))
    ax0 = plt.subplot(231)
    ax0.set_title('fp1')
    ax0.imshow(self.fp1_mean_img_raw, cmap='jet')
    ax0.axis('off')

    ax1 = plt.subplot(232)
    ax1.set_title('fp2')
    img1 = ax1.imshow(self.fp2_mean_img_raw, cmap='jet')
    img1.set_clim(vmin=v_min, vmax=v_max)
    div1 = make_axes_locatable(ax1)
    cax1 = div1.append_axes('right', size='3%', pad=0.1)
    plt.colorbar(img1, cax=cax1)
    ax1.axis('off')

    ax4 = plt.subplot(233)
    ax4.imshow(self.fp2_mean_img_raw, cmap='jet')
    ax4.imshow(ma.masked_where(~self.narrow_proc_mask, self.narrow_proc_mask),
               cmap='Greys', alpha=.4)
    ax4.imshow(ma.masked_where(~self.proc_mask, self.proc_mask),
               cmap='Greys', alpha=.25)
    ax4.set_title('processes mask')
    ax4.axis('off')

    ax2 = plt.subplot(413)
    ax2.plot(np.mean(self.fp1_img_raw, axis=(1,2), where=self.proc_mask),
             label='fp1 raw', color='k')
    ax2.plot(np.mean(self.fp1_img_corr, axis=(1,2), where=self.proc_mask),
             label='fp1 corrected', linestyle='--', color='k')
    ax2.plot(np.mean(self.fp2_img_raw, axis=(1,2), where=self.proc_mask),
             label='fp2 raw', color='r')
    ax2.plot(np.mean(self.fp2_img_corr, axis=(1,2), where=self.proc_mask),
             label='fp2 corrected', linestyle='--', color='r')
    ax2.set_xlabel('Frame num')
    ax2.set_ylabel('Int, a.u.')
    ax2.set_title('Int. profile')
    ax2.legend()

    ax3 = plt.subplot(414)
    ax3.plot(fp2_der_p, linestyle='--', color='r')
    ax3.plot(fp1_der_p, linestyle='--', color='k')
    ax3.plot(fp2_der_w, color='r')
    ax3.plot(fp1_der_w, color='k')
    ax3.set_xlabel('Frame num')
    ax3.set_ylabel('Norm. der.')
    ax3.set_title('Der. profile')
    ax3.legend()

    plt.suptitle(self.img_name)
    plt.tight_layout()
    plt.show()

get_all_channels

Returns all individual channels blurred with Gaussian filter (with sigma wf_sigma).

Could be useful for FRET calculation.

Returns:
  • ch0_img( ndarray[t, x, y] ) –

    image series for channel 0

  • ch1_img( ndarray[t, x, y] ) –

    image series for channel 0

  • ch2_img( ndarray[t, x, y] ) –

    image series for channel 0

  • ch3_img( ndarray[t, x, y] ) –

    image series for channel 0

src/domb/reg_type/wf_x2_m2.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
def get_all_channels(self):
    """ Returns all individual channels blurred with Gaussian filter (with sigma `wf_sigma`).

    Could be useful for FRET calculation.

    Returns
    -------
    ch0_img: ndarray [t,x,y]
        image series for channel 0
    ch1_img: ndarray [t,x,y]
        image series for channel 0
    ch2_img: ndarray [t,x,y]
        image series for channel 0
    ch3_img: ndarray [t,x,y]
        image series for channel 0

    """
    # chennels split
    ch0_img = np.asarray([filters.gaussian(frame, sigma=self.gauss_sigma) \
                          for frame in self.img_raw[:,:,:,0]])  # 435-fp1  DD
    ch1_img = np.asarray([filters.gaussian(frame, sigma=self.gauss_sigma) \
                          for frame in self.img_raw[:,:,:,1]])  # 435-fp2  DA
    ch2_img = np.asarray([filters.gaussian(frame, sigma=self.gauss_sigma) \
                          for frame in self.img_raw[:,:,:,2]])  # 505-fp1  AD
    ch3_img = np.asarray([filters.gaussian(frame, sigma=self.gauss_sigma) \
                          for frame in self.img_raw[:,:,:,3]])  # 505-fp2  AA

    return ch0_img, ch1_img, ch2_img, ch3_img

hist_pic

Plotting of histogram for individual channels (for channel mean intensity frame).

src/domb/reg_type/wf_x2_m2.py
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
def hist_pic(self):
    """ Plotting of histogram for individual channels
    (for channel mean intensity frame).

    """

    ch0_ctrl = np.mean(self.img_raw[:,:,:,0], axis=0)
    ch1_ctrl = np.mean(self.img_raw[:,:,:,1], axis=0)
    ch2_ctrl = np.mean(self.img_raw[:,:,:,2], axis=0)
    ch3_ctrl = np.mean(self.img_raw[:,:,:,3], axis=0)

    plt.figure(figsize=(20,10))
    ax0 = plt.subplot()
    ax0.hist(ch0_ctrl.ravel(), bins=256, alpha=.5, label='Ch 0 (fp1-435)', color='r')
    ax0.hist(ch1_ctrl.ravel(), bins=256, alpha=.5, label='Ch 1 (fp2-435)', color='g')
    ax0.hist(ch2_ctrl.ravel(), bins=256, alpha=.5, label='Ch 2 (fp1-505)', color='y')
    ax0.hist(ch3_ctrl.ravel(), bins=256, alpha=.5, label='Ch 3 (fp2-505)', color='b')
    ax0.legend()

    plt.show()

processes_mask_pic

Plotting of cell processes mask (narrow and extended) overlay with control fluorescence image (fp2_mean_img_raw).

src/domb/reg_type/wf_x2_m2.py
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def processes_mask_pic(self):
    """ Plotting of cell processes mask (narrow and extended)
    overlay with control fluorescence image (`fp2_mean_img_raw`).

    """
    plt.figure(figsize=(10,190))
    ax0 = plt.subplot()
    ax0.imshow(self.fp2_mean_img_raw, cmap='jet')
    ax0.imshow(ma.masked_where(~self.narrow_proc_mask, self.narrow_proc_mask),
               cmap='Greys', alpha=.4)
    ax0.imshow(ma.masked_where(~self.proc_mask, self.proc_mask),
               cmap='Greys', alpha=.25)
    ax0.axis('off')

    plt.tight_layout()
    plt.show()