-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadCzi5D.py
74 lines (52 loc) · 2.85 KB
/
LoadCzi5D.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
"""This function loads .lsm files.
Given the filename of a .lsm file, this function gives as output the matrices
of the red and green channels maximum intensity projected plus the green channel
as it is. Inputs are the file-name and the channel number for nuclei and spots.
"""
import numpy as np
import czifile
# from PyQt5 import QtWidgets
class LoadCzi5D:
"""Only class, does all the job"""
def __init__(self, fname, nucs_spts_ch):
file_array = np.squeeze(czifile.imread(fname))
if len(file_array.shape) == 5: # case you have more than a time frame
c, steps, z, x_len, y_len = file_array.shape
# pbar = ProgressBar(total1=steps)
# pbar.show()
red_mtx = np.zeros((steps, x_len, y_len), dtype=np.int32)
green_mtx = np.zeros((steps, x_len, y_len), dtype=np.int32)
for t in range(steps): # maximum intensity projection
# pbar.update_progressbar(t)
for x in range(x_len):
red_mtx[t, x, :] = file_array[nucs_spts_ch[0], t, :, x, :].max(0)
green_mtx[t, x, :] = file_array[nucs_spts_ch[1], t, :, x, :].max(0)
# pbar.close()
self.green4D = file_array[0, :, :, :, :]
else: # case you have just one time frame
c, z, x_len, y_len = file_array.shape
red_mtx = np.zeros((x_len, y_len))
green_mtx = np.zeros((x_len, y_len))
for x in range(x_len): # maximum intensity projection
red_mtx[x, :] = file_array[nucs_spts_ch[0], :, x, :].max(0)
green_mtx[x, :] = file_array[nucs_spts_ch[1], :, x, :].max(0)
self.green4D = file_array[nucs_spts_ch[1], :, :, :]
self.red_mtx = red_mtx
self.green_mtx = green_mtx
# class ProgressBar(QtWidgets.QWidget):
# """Simple progress bar widget"""
# def __init__(self, parent=None, total1=20):
# super(ProgressBar, self).__init__(parent)
# self.name_line1 = QtWidgets.QLineEdit()
# self.progressbar1 = QtWidgets.QProgressBar()
# self.progressbar1.setMinimum(1)
# self.progressbar1.setMaximum(total1)
# main_layout = QtWidgets.QGridLayout()
# main_layout.addWidget(self.progressbar1, 0, 0)
# self.setLayout(main_layout)
# self.setWindowTitle("Progress")
# self.setGeometry(500, 300, 300, 50)
# def update_progressbar(self, val1):
# """Progress bar updater"""
# self.progressbar1.setValue(val1)
# QtWidgets.qApp.processEvents()