@@ -33,36 +33,41 @@ def __init__(self):
33
33
self .ui = WindowTemplate ()
34
34
self .ui .setupUi (self )
35
35
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 ])
43
52
self .roi .translateSnap = True
44
53
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 )
52
56
53
- #setup plot
57
+ #setup rgb plot
54
58
self .rgb_plot_layout = pg .GraphicsLayoutWidget ()
55
59
self .ui .rgb_plot_groupBox .layout ().addWidget (self .rgb_plot_layout )
56
60
self .rgb_plot = self .rgb_plot_layout .addPlot ()
57
61
58
62
#set up ui signals
59
- self .roi .sigRegionChanged .connect (self .line_profile_update_plot )
60
63
self .ui .load_image_pushButton .clicked .connect (self .load_image )
61
64
self .ui .custom_pixel_size_checkBox .stateChanged .connect (self .switch_custom_pixel_size )
62
65
self .ui .update_scaling_factor_pushButton .clicked .connect (self .reload_image )
63
66
self .ui .spot_radioButton .toggled .connect (self .update_camera )
64
67
self .ui .custom_pixel_size_spinBox .valueChanged .connect (self .update_scaling_factor )
65
68
69
+ self .update_camera () #initialize camera pixel size
70
+ self .update_scaling_factor () #initialize scaling_factor
66
71
self .show ()
67
72
68
73
#row major. invert y false, rotate false
@@ -91,20 +96,18 @@ def resize_to_scaling_factor(self, image):
91
96
if self .ui .greyscale_checkBox .isChecked ():
92
97
image = image .convert ("L" ) #convert to greyscale
93
98
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 ]
97
102
98
103
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 )
103
108
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 )
108
111
109
112
if self .ui .vertical_radioButton .isChecked ():
110
113
roi_height = self .scaling_factor * height
@@ -113,25 +116,16 @@ def resize_to_scaling_factor(self, image):
113
116
roi_height = self .scaling_factor * width
114
117
self .roi .setSize ([roi_height , height ])
115
118
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 ()
123
119
self .line_profile_update_plot ()
124
120
except :
125
121
pass
126
122
127
123
def line_profile_update_plot (self ):
128
124
""" Handle line profile for intensity sum viewbox """
129
125
self .rgb_plot .clear ()
130
- image = self .imv .getProcessedImage ()
131
126
132
127
# 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 )
135
129
if data is None :
136
130
return
137
131
0 commit comments