Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 73bb638

Browse files
author
LAKESIDE\LindaT18
committed
image_analysis: add grayscale option, flim: average instead of sum for line profile
1 parent 11b21fe commit 73bb638

3 files changed

Lines changed: 77 additions & 29 deletions

File tree

PythonGUI_apps/FLIM_analysis/FLIM_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def line_profile_update_plot(self):
129129
data, coords = roi.getArrayRegion(image.view(np.ndarray), self.ui.intensity_sums_viewBox.imageItem, axes, returnMappedCoords=True)
130130

131131
#calculate sums along columns in region
132-
sums_to_plot = np.sum(data, axis=0)
132+
sums_to_plot = np.mean(data, axis=0)
133133

134134
#get scan x-coordinates in region
135135
x_values = coords[1][0]

PythonGUI_apps/Image_analysis/Image_analysis.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@ def __init__(self):
3535
self.roi = self.imv.roi
3636
self.roi.translateSnap = True
3737
self.roi.scaleSnap = True
38+
self.update_camera() #initialize camera pixel size
3839
self.update_scaling_factor() #initialize scaling_factor
3940

40-
self.roi_plot = self.imv.getRoiPlot().getPlotItem()
41-
41+
self.roi_plot = self.imv.getRoiPlot().getPlotItem() #get roi plot
4242
self.ui.image_groupBox.layout().addWidget(self.imv)
4343

4444
#set up ui signals
4545
self.roi.sigRegionChanged.connect(self.line_profile_update_plot)
4646
self.ui.load_image_pushButton.clicked.connect(self.load_image)
4747
self.ui.custom_pixel_size_checkBox.stateChanged.connect(self.switch_custom_pixel_size)
4848
self.ui.update_scaling_factor_pushButton.clicked.connect(self.update_scaling_factor)
49+
self.ui.spot_radioButton.toggled.connect(self.update_camera)
4950

5051
self.num_plots = 0
5152
self.show()
@@ -57,26 +58,30 @@ def load_image(self):
5758
try:
5859
file = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', os.getcwd())
5960
self.original_image = Image.open(file[0])
60-
self.original_image = self.original_image.rotate(-90, expand=True)
61+
#self.original_image = self.original_image.rotate(-90, expand=True)
6162
self.resize_to_scaling_factor(self.original_image)
6263
except Exception as err:
6364
print(format(err))
6465

6566
def resize_to_scaling_factor(self, image):
67+
"""
68+
Handles loading of image according to scaling_factor
69+
"""
6670
image = image.resize((round(image.size[0]*self.scaling_factor), round(image.size[1]*self.scaling_factor)))
67-
image_array = np.asarray(image)
71+
if self.ui.greyscale_checkBox.isChecked():
72+
image = image.convert("L") #convert to greyscale
73+
image_array = np.asarray(image).T #correct numpy array auto-flip
6874
width = image_array.shape[0]
6975
height = image_array.shape[1]
7076
try:
71-
x_vals = np.arange(width)
77+
x_vals = np.arange(width) #imv x-axis
7278
self.imv.setImage(img=image_array, xvals= x_vals)
7379
self.roi.setPos((0,0))
7480
self.roi.setSize([width, height * self.scaling_factor]) #set line roi
7581
self.line_profile_update_plot()
7682
except:
7783
pass
7884

79-
8085
def line_profile_update_plot(self):
8186
""" Handle line profile for intensity sum viewbox """
8287
self.roi_plot.clear()
@@ -118,17 +123,22 @@ def update_scaling_factor(self):
118123
if self.ui.custom_pixel_size_checkBox.isChecked():
119124
self.scaling_factor = self.ui.custom_pixel_size_spinBox.value()
120125
else:
121-
pixel_size = 7.4
122-
self.scaling_factor = pixel_size/int(self.ui.magnification_comboBox.currentText())
123-
self.roi.snapSize = self.scaling_factor
126+
self.scaling_factor = self.camera_pixel_size/int(self.ui.magnification_comboBox.currentText())
127+
self.roi.snapSize = self.scaling_factor #roi snaps to multiples of scaling_factor
124128
if hasattr(self, "original_image"):
125-
self.resize_to_scaling_factor(self.original_image)
129+
self.resize_to_scaling_factor(self.original_image) #resize image, sets up roi
126130

127131
def switch_custom_pixel_size(self):
128132
checked = self.ui.custom_pixel_size_checkBox.isChecked()
129133
self.ui.custom_pixel_size_spinBox.setEnabled(checked)
130134
self.ui.magnification_comboBox.setEnabled(not checked)
131135

136+
def update_camera(self):
137+
if self.ui.spot_radioButton.isChecked():
138+
self.camera_pixel_size = 7.4
139+
elif self.ui.pixera_radioButton.isChecked():
140+
self.camera_pixel_size = 0
141+
132142
def close_application(self):
133143
choice = QtGui.QMessageBox.question(self, 'EXIT!',
134144
"Do you want to exit the app?",

PythonGUI_apps/Image_analysis/image_analysis_gui.ui

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>1059</width>
9+
<width>1029</width>
1010
<height>743</height>
1111
</rect>
1212
</property>
@@ -51,14 +51,21 @@
5151
</item>
5252
<item row="0" column="0">
5353
<layout class="QGridLayout" name="gridLayout">
54-
<item row="1" column="2">
55-
<widget class="QCheckBox" name="custom_pixel_size_checkBox">
54+
<item row="6" column="0">
55+
<widget class="QPushButton" name="load_image_pushButton">
5656
<property name="text">
57-
<string>Custom pixel size (um)</string>
57+
<string>Load image</string>
58+
</property>
59+
</widget>
60+
</item>
61+
<item row="0" column="0">
62+
<widget class="QCheckBox" name="greyscale_checkBox">
63+
<property name="text">
64+
<string>Greyscale image</string>
5865
</property>
5966
</widget>
6067
</item>
61-
<item row="0" column="3">
68+
<item row="3" column="1">
6269
<widget class="QComboBox" name="magnification_comboBox">
6370
<item>
6471
<property name="text">
@@ -75,30 +82,61 @@
7582
<string>100</string>
7683
</property>
7784
</item>
85+
<item>
86+
<property name="text">
87+
<string>150</string>
88+
</property>
89+
</item>
7890
</widget>
7991
</item>
80-
<item row="1" column="3">
81-
<widget class="QDoubleSpinBox" name="custom_pixel_size_spinBox">
82-
<property name="enabled">
83-
<bool>false</bool>
84-
</property>
85-
</widget>
86-
</item>
87-
<item row="0" column="2">
92+
<item row="3" column="0">
8893
<widget class="QLabel" name="label_7">
8994
<property name="text">
9095
<string>Magnification</string>
9196
</property>
9297
</widget>
9398
</item>
94-
<item row="0" column="0" colspan="2">
95-
<widget class="QPushButton" name="load_image_pushButton">
99+
<item row="5" column="0">
100+
<widget class="QCheckBox" name="custom_pixel_size_checkBox">
96101
<property name="text">
97-
<string>Load image</string>
102+
<string>Custom pixel size (um)</string>
103+
</property>
104+
</widget>
105+
</item>
106+
<item row="5" column="1">
107+
<widget class="QDoubleSpinBox" name="custom_pixel_size_spinBox">
108+
<property name="enabled">
109+
<bool>false</bool>
110+
</property>
111+
</widget>
112+
</item>
113+
<item row="2" column="0" colspan="2">
114+
<widget class="QGroupBox" name="groupBox">
115+
<property name="title">
116+
<string>Camera</string>
98117
</property>
118+
<layout class="QVBoxLayout" name="verticalLayout">
119+
<item>
120+
<widget class="QRadioButton" name="spot_radioButton">
121+
<property name="text">
122+
<string>SPOT</string>
123+
</property>
124+
<property name="checked">
125+
<bool>true</bool>
126+
</property>
127+
</widget>
128+
</item>
129+
<item>
130+
<widget class="QRadioButton" name="pixera_radioButton">
131+
<property name="text">
132+
<string>Pixera</string>
133+
</property>
134+
</widget>
135+
</item>
136+
</layout>
99137
</widget>
100138
</item>
101-
<item row="2" column="2" colspan="2">
139+
<item row="8" column="0">
102140
<widget class="QPushButton" name="update_scaling_factor_pushButton">
103141
<property name="text">
104142
<string>Update scaling factor</string>
@@ -117,7 +155,7 @@
117155
<rect>
118156
<x>0</x>
119157
<y>0</y>
120-
<width>1059</width>
158+
<width>1029</width>
121159
<height>31</height>
122160
</rect>
123161
</property>

0 commit comments

Comments
 (0)