@@ -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?" ,
0 commit comments