Skip to content

Commit 45d4ac4

Browse files
author
LAKESIDE\LindaT18
committed
use separate image plot instead of imageview
1 parent d9844ad commit 45d4ac4

File tree

1 file changed

+31
-37
lines changed

1 file changed

+31
-37
lines changed

PythonGUI_apps/Image_analysis/Image_analysis.py

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,41 @@ def __init__(self):
3333
self.ui = WindowTemplate()
3434
self.ui.setupUi(self)
3535

36-
#setup imageview
37-
self.imv = pg.ImageView()
38-
self.imv.getView().setAspectLocked(lock=False, ratio=1)
39-
self.imv.getView().setMouseEnabled(x=True, y=True)
40-
self.imv.getView().invertY(False)
41-
self.imv.ui.roiBtn.setEnabled(False)
42-
self.roi = self.imv.roi
36+
#setup image plot
37+
self.image_plot_layout=pg.GraphicsLayoutWidget()
38+
self.ui.image_groupBox.layout().addWidget(self.image_plot_layout)
39+
self.image_plot = self.image_plot_layout.addPlot()
40+
self.img_item = pg.ImageItem()
41+
self.image_plot.addItem(self.img_item)
42+
self.image_plot_view = self.image_plot.getViewBox()
43+
44+
#setup lookup table
45+
self.hist_lut = pg.HistogramLUTItem()
46+
self.image_plot_layout.addItem(self.hist_lut)
47+
48+
#region of interest - allows user to select scan area
49+
self.roi = pg.ROI([0,0],[10, 10], movable=True)
50+
self.roi.addScaleHandle([1, 1], [0, 0])
51+
self.roi.addRotateHandle([0, 0], [1, 1])
4352
self.roi.translateSnap = True
4453
self.roi.scaleSnap = True
45-
#self.roi.removeHandle(1)
46-
#self.roi.addScaleHandle([0, 0], [1, 1])
47-
self.update_camera() #initialize camera pixel size
48-
self.update_scaling_factor() #initialize scaling_factor
49-
50-
self.roi_plot = self.imv.getRoiPlot().getPlotItem() #get roi plot
51-
self.ui.image_groupBox.layout().addWidget(self.imv)
54+
self.roi.sigRegionChanged.connect(self.line_profile_update_plot)
55+
self.image_plot.addItem(self.roi)
5256

53-
#setup plot
57+
#setup rgb plot
5458
self.rgb_plot_layout=pg.GraphicsLayoutWidget()
5559
self.ui.rgb_plot_groupBox.layout().addWidget(self.rgb_plot_layout)
5660
self.rgb_plot = self.rgb_plot_layout.addPlot()
5761

5862
#set up ui signals
59-
self.roi.sigRegionChanged.connect(self.line_profile_update_plot)
6063
self.ui.load_image_pushButton.clicked.connect(self.load_image)
6164
self.ui.custom_pixel_size_checkBox.stateChanged.connect(self.switch_custom_pixel_size)
6265
self.ui.update_scaling_factor_pushButton.clicked.connect(self.reload_image)
6366
self.ui.spot_radioButton.toggled.connect(self.update_camera)
6467
self.ui.custom_pixel_size_spinBox.valueChanged.connect(self.update_scaling_factor)
6568

69+
self.update_camera() #initialize camera pixel size
70+
self.update_scaling_factor() #initialize scaling_factor
6671
self.show()
6772

6873
#row major. invert y false, rotate false
@@ -91,20 +96,18 @@ def resize_to_scaling_factor(self, image):
9196
if self.ui.greyscale_checkBox.isChecked():
9297
image = image.convert("L") #convert to greyscale
9398

94-
image_array = np.array(image)
95-
width = image_array.shape[0]
96-
height = image_array.shape[1]
99+
self.image_array = np.array(image)
100+
width = self.image_array.shape[0]
101+
height = self.image_array.shape[1]
97102

98103
try:
99-
if self.ui.vertical_radioButton.isChecked():
100-
x_vals = np.arange(width)
101-
elif self.ui.horizontal_radioButton.isChecked():
102-
x_vals = np.arange(height)
104+
#set image bounds with qrect
105+
self.img_item_rect = QtCore.QRectF(0, 0, width, height)
106+
self.img_item.setImage(image=self.image_array)
107+
self.img_item.setRect(self.img_item_rect)
103108

104-
if self.ui.pixera_radioButton.isChecked():
105-
x_vals = x_vals * self.scaling_factor
106-
107-
self.imv.setImage(image_array, xvals= x_vals)
109+
if self.ui.greyscale_checkBox.isChecked():
110+
self.hist_lut.setImageItem(self.img_item)
108111

109112
if self.ui.vertical_radioButton.isChecked():
110113
roi_height = self.scaling_factor * height
@@ -113,25 +116,16 @@ def resize_to_scaling_factor(self, image):
113116
roi_height = self.scaling_factor * width
114117
self.roi.setSize([roi_height, height])
115118

116-
self.roi.setPos((0, 0))
117-
118-
scale = pg.ScaleBar(size=1,suffix='um')
119-
scale.setParentItem(self.imv.view)
120-
scale.anchor((1, 1), (1, 1), offset=(-30, -30))
121-
self.imv.view.sigRangeChanged.connect(lambda: updateDelay(scale, 10))
122-
self.roi.show()
123119
self.line_profile_update_plot()
124120
except:
125121
pass
126122

127123
def line_profile_update_plot(self):
128124
""" Handle line profile for intensity sum viewbox """
129125
self.rgb_plot.clear()
130-
image = self.imv.getProcessedImage()
131126

132127
# Extract image data from ROI
133-
axes = (self.imv.axes['x'], self.imv.axes['y'])
134-
data, coords = self.roi.getArrayRegion(image.view(np.ndarray), self.imv.imageItem, axes, returnMappedCoords=True)
128+
data, coords = self.roi.getArrayRegion(self.image_array, self.img_item, returnMappedCoords=True)
135129
if data is None:
136130
return
137131

0 commit comments

Comments
 (0)