@@ -37,18 +37,23 @@ def __init__(self):
37
37
self .imv .getView ().setAspectLocked (lock = False , ratio = 1 )
38
38
self .imv .getView ().setMouseEnabled (x = True , y = True )
39
39
self .imv .getView ().invertY (False )
40
+ self .imv .ui .roiBtn .setEnabled (False )
40
41
self .roi = self .imv .roi
41
-
42
42
self .roi .translateSnap = True
43
43
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])
46
46
self .update_camera () #initialize camera pixel size
47
47
self .update_scaling_factor () #initialize scaling_factor
48
48
49
49
self .roi_plot = self .imv .getRoiPlot ().getPlotItem () #get roi plot
50
50
self .ui .image_groupBox .layout ().addWidget (self .imv )
51
51
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
+
52
57
#set up ui signals
53
58
self .roi .sigRegionChanged .connect (self .line_profile_update_plot )
54
59
self .ui .load_image_pushButton .clicked .connect (self .load_image )
@@ -90,24 +95,37 @@ def resize_to_scaling_factor(self, image):
90
95
height = image_array .shape [1 ]
91
96
92
97
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
+
94
103
if self .ui .pixera_radioButton .isChecked ():
95
104
x_vals = x_vals * self .scaling_factor
105
+
96
106
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
+
98
115
self .roi .setPos ((0 , 0 ))
99
- self . roi . setSize ([ width , roi_height ])
116
+
100
117
scale = pg .ScaleBar (size = 1 ,suffix = 'um' )
101
118
scale .setParentItem (self .imv .view )
102
119
scale .anchor ((1 , 1 ), (1 , 1 ), offset = (- 30 , - 30 ))
103
120
self .imv .view .sigRangeChanged .connect (lambda : updateDelay (scale , 10 ))
121
+ self .roi .show ()
104
122
self .line_profile_update_plot ()
105
123
except :
106
124
pass
107
125
108
126
def line_profile_update_plot (self ):
109
127
""" Handle line profile for intensity sum viewbox """
110
- self .roi_plot .clear ()
128
+ self .rgb_plot .clear ()
111
129
image = self .imv .getProcessedImage ()
112
130
113
131
# Extract image data from ROI
@@ -116,28 +134,40 @@ def line_profile_update_plot(self):
116
134
if data is None :
117
135
return
118
136
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
+
120
142
if self .ui .pixera_radioButton .isChecked ():
121
143
x_values = x_values * self .scaling_factor
122
144
123
145
#calculate average along columns in region
124
146
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 )
126
151
try :
127
- self .roi_plot .plot (x_values , avg_to_plot )
152
+ self .rgb_plot .plot (x_values , avg_to_plot )
128
153
except :
129
154
pass
130
155
elif len (data .shape ) > 2 : #if rgb arrays, plot individual components
131
156
r_values = data [:,:,0 ]
132
157
g_values = data [:,:,1 ]
133
158
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 )
137
167
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' )
141
171
except Exception as e :
142
172
pass
143
173
@@ -170,6 +200,7 @@ def update_camera(self):
170
200
self .camera_pixel_size = 3
171
201
self .ui .greyscale_checkBox .setChecked (True )
172
202
self .update_scaling_factor ()
203
+
173
204
def close_application (self ):
174
205
choice = QtGui .QMessageBox .question (self , 'EXIT!' ,
175
206
"Do you want to exit the app?" ,
0 commit comments