Skip to content

Commit c196dda

Browse files
author
LAKESIDE\LindaT18
committed
initial work on separate rgb plot and horizontal rgb avg
1 parent 5f21a07 commit c196dda

File tree

3 files changed

+75
-55
lines changed

3 files changed

+75
-55
lines changed

PythonGUI_apps/Image_analysis/Image_analysis.py

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,23 @@ def __init__(self):
3737
self.imv.getView().setAspectLocked(lock=False, ratio=1)
3838
self.imv.getView().setMouseEnabled(x=True, y=True)
3939
self.imv.getView().invertY(False)
40+
self.imv.ui.roiBtn.setEnabled(False)
4041
self.roi = self.imv.roi
41-
4242
self.roi.translateSnap = True
4343
self.roi.scaleSnap = True
44-
self.roi.removeHandle(1)
45-
self.roi.addScaleHandle([0, 0], [1, 1])
44+
#self.roi.removeHandle(1)
45+
#self.roi.addScaleHandle([0, 0], [1, 1])
4646
self.update_camera() #initialize camera pixel size
4747
self.update_scaling_factor() #initialize scaling_factor
4848

4949
self.roi_plot = self.imv.getRoiPlot().getPlotItem() #get roi plot
5050
self.ui.image_groupBox.layout().addWidget(self.imv)
5151

52+
#setup plot
53+
self.rgb_plot_layout=pg.GraphicsLayoutWidget()
54+
self.ui.rgb_plot_groupBox.layout().addWidget(self.rgb_plot_layout)
55+
self.rgb_plot = self.rgb_plot_layout.addPlot()
56+
5257
#set up ui signals
5358
self.roi.sigRegionChanged.connect(self.line_profile_update_plot)
5459
self.ui.load_image_pushButton.clicked.connect(self.load_image)
@@ -90,24 +95,37 @@ def resize_to_scaling_factor(self, image):
9095
height = image_array.shape[1]
9196

9297
try:
93-
x_vals = np.arange(width)
98+
if self.ui.vertical_radioButton.isChecked():
99+
x_vals = np.arange(width)
100+
elif self.ui.horizontal_radioButton.isChecked():
101+
x_vals = np.arange(height)
102+
94103
if self.ui.pixera_radioButton.isChecked():
95104
x_vals = x_vals * self.scaling_factor
105+
96106
self.imv.setImage(image_array, xvals= x_vals)
97-
roi_height = self.scaling_factor * height
107+
108+
if self.ui.vertical_radioButton.isChecked():
109+
roi_height = self.scaling_factor * height
110+
self.roi.setSize([width, roi_height])
111+
elif self.ui.horizontal_radioButton.isChecked():
112+
roi_height = self.scaling_factor * width
113+
self.roi.setSize([roi_height, height])
114+
98115
self.roi.setPos((0, 0))
99-
self.roi.setSize([width, roi_height])
116+
100117
scale = pg.ScaleBar(size=1,suffix='um')
101118
scale.setParentItem(self.imv.view)
102119
scale.anchor((1, 1), (1, 1), offset=(-30, -30))
103120
self.imv.view.sigRangeChanged.connect(lambda: updateDelay(scale, 10))
121+
self.roi.show()
104122
self.line_profile_update_plot()
105123
except:
106124
pass
107125

108126
def line_profile_update_plot(self):
109127
""" Handle line profile for intensity sum viewbox """
110-
self.roi_plot.clear()
128+
self.rgb_plot.clear()
111129
image = self.imv.getProcessedImage()
112130

113131
# Extract image data from ROI
@@ -116,28 +134,40 @@ def line_profile_update_plot(self):
116134
if data is None:
117135
return
118136

119-
x_values = coords[0,:,0]
137+
if self.ui.vertical_radioButton.isChecked():
138+
x_values = coords[0,:,0]
139+
elif self.ui.horizontal_radioButton.isChecked():
140+
x_values = coords[1,0,:]
141+
120142
if self.ui.pixera_radioButton.isChecked():
121143
x_values = x_values * self.scaling_factor
122144

123145
#calculate average along columns in region
124146
if len(data.shape) == 2: #if grayscale, average intensities
125-
avg_to_plot = np.mean(data, axis=-1)
147+
if self.ui.vertical_radioButton.isChecked():
148+
avg_to_plot = np.mean(data, axis=-1)
149+
elif self.ui.horizontal_radioButton.isChecked():
150+
avg_to_plot = np.mean(data, axis=0)
126151
try:
127-
self.roi_plot.plot(x_values, avg_to_plot)
152+
self.rgb_plot.plot(x_values, avg_to_plot)
128153
except:
129154
pass
130155
elif len(data.shape) > 2: #if rgb arrays, plot individual components
131156
r_values = data[:,:,0]
132157
g_values = data[:,:,1]
133158
b_values = data[:,:,2]
134-
r_avg = np.mean(r_values, axis=-1) #average red values across columns
135-
g_avg = np.mean(g_values, axis=-1) #average green values
136-
b_avg = np.mean(b_values, axis=-1) #average blue values
159+
if self.ui.vertical_radioButton.isChecked():
160+
r_avg = np.mean(r_values, axis=-1) #average red values across columns
161+
g_avg = np.mean(g_values, axis=-1) #average green values
162+
b_avg = np.mean(b_values, axis=-1) #average blue values
163+
elif self.ui.horizontal_radioButton.isChecked():
164+
r_avg = np.mean(r_values, axis=0)
165+
g_avg = np.mean(g_values, axis=0)
166+
b_avg = np.mean(b_values, axis=0)
137167
try:
138-
self.roi_plot.plot(x_values, r_avg, pen='r')
139-
self.roi_plot.plot(x_values, g_avg, pen='g')
140-
self.roi_plot.plot(x_values, b_avg, pen='b')
168+
self.rgb_plot.plot(x_values, r_avg, pen='r')
169+
self.rgb_plot.plot(x_values, g_avg, pen='g')
170+
self.rgb_plot.plot(x_values, b_avg, pen='b')
141171
except Exception as e:
142172
pass
143173

@@ -170,6 +200,7 @@ def update_camera(self):
170200
self.camera_pixel_size = 3
171201
self.ui.greyscale_checkBox.setChecked(True)
172202
self.update_scaling_factor()
203+
173204
def close_application(self):
174205
choice = QtGui.QMessageBox.question(self, 'EXIT!',
175206
"Do you want to exit the app?",

PythonGUI_apps/Image_analysis/image_analysis_gui.ui

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,6 @@
1818
</property>
1919
<widget class="QWidget" name="centralwidget">
2020
<layout class="QGridLayout" name="gridLayout_2">
21-
<item row="0" column="0">
22-
<widget class="QGroupBox" name="image_groupBox">
23-
<property name="sizePolicy">
24-
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
25-
<horstretch>0</horstretch>
26-
<verstretch>0</verstretch>
27-
</sizepolicy>
28-
</property>
29-
<property name="minimumSize">
30-
<size>
31-
<width>600</width>
32-
<height>0</height>
33-
</size>
34-
</property>
35-
<property name="title">
36-
<string>Image</string>
37-
</property>
38-
<layout class="QGridLayout" name="gridLayout_3"/>
39-
</widget>
40-
</item>
4121
<item row="0" column="1">
4222
<widget class="QGroupBox" name="groupBox_2">
4323
<property name="title">
@@ -174,6 +154,34 @@
174154
</layout>
175155
</widget>
176156
</item>
157+
<item row="0" column="0">
158+
<widget class="QGroupBox" name="image_groupBox">
159+
<property name="sizePolicy">
160+
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
161+
<horstretch>0</horstretch>
162+
<verstretch>0</verstretch>
163+
</sizepolicy>
164+
</property>
165+
<property name="minimumSize">
166+
<size>
167+
<width>600</width>
168+
<height>0</height>
169+
</size>
170+
</property>
171+
<property name="title">
172+
<string>Image</string>
173+
</property>
174+
<layout class="QGridLayout" name="gridLayout_3"/>
175+
</widget>
176+
</item>
177+
<item row="1" column="0" colspan="2">
178+
<widget class="QGroupBox" name="rgb_plot_groupBox">
179+
<property name="title">
180+
<string>RGB Plot</string>
181+
</property>
182+
<layout class="QGridLayout" name="gridLayout_6"/>
183+
</widget>
184+
</item>
177185
</layout>
178186
</widget>
179187
<widget class="QMenuBar" name="menubar">

PythonGUI_apps/test_im.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)