1010# local modules
1111
1212pg .mkQApp ()
13- pg .setConfigOption ('imageAxisOrder' , 'row -major' )
13+ pg .setConfigOption ('imageAxisOrder' , 'col -major' )
1414
1515base_path = Path (__file__ ).parent
1616file_path = (base_path / "image_analysis_gui.ui" ).resolve ()
@@ -36,11 +36,13 @@ def __init__(self):
3636 self .imv = pg .ImageView ()
3737 self .imv .getView ().setAspectLocked (lock = False , ratio = 1 )
3838 self .imv .getView ().setMouseEnabled (x = True , y = True )
39- # self.imv.getView().invertY(False)
39+ self .imv .getView ().invertY (False )
4040 self .roi = self .imv .roi
4141
4242 self .roi .translateSnap = True
4343 self .roi .scaleSnap = True
44+ self .roi .removeHandle (1 )
45+ self .roi .addScaleHandle ([0 , 0 ], [1 , 1 ])
4446 self .update_camera () #initialize camera pixel size
4547 self .update_scaling_factor () #initialize scaling_factor
4648
@@ -53,17 +55,19 @@ def __init__(self):
5355 self .ui .custom_pixel_size_checkBox .stateChanged .connect (self .switch_custom_pixel_size )
5456 self .ui .update_scaling_factor_pushButton .clicked .connect (self .reload_image )
5557 self .ui .spot_radioButton .toggled .connect (self .update_camera )
58+ self .ui .custom_pixel_size_spinBox .valueChanged .connect (self .update_scaling_factor )
5659
5760 self .show ()
5861
62+ #row major. invert y false, rotate false
5963 def load_image (self ):
6064 """
6165 Prompts the user to select a text file containing image data.
6266 """
6367 try :
6468 file = QtWidgets .QFileDialog .getOpenFileName (self , 'Open file' , os .getcwd ())
6569 self .original_image = Image .open (file [0 ])
66- # self.original_image = self.original_image.rotate(-90, expand=True) #correct image orientation
70+ self .original_image = self .original_image .rotate (- 90 , expand = True ) #correct image orientation
6771 self .resize_to_scaling_factor (self .original_image )
6872 except Exception as err :
6973 print (format (err ))
@@ -72,8 +76,6 @@ def resize_to_scaling_factor(self, image):
7276 """
7377 Handles loading of image according to scaling_factor
7478 """
75- self .update_camera () #initialize camera pixel size
76- self .update_scaling_factor () #initialize scaling_factor
7779
7880 if self .ui .pixera_radioButton .isChecked ():
7981 image = self .original_image
@@ -86,18 +88,15 @@ def resize_to_scaling_factor(self, image):
8688 image_array = np .array (image )
8789 width = image_array .shape [0 ]
8890 height = image_array .shape [1 ]
89- if self .ui .pixera_radioButton .isChecked ():
90- width = width * self .scaling_factor
91- height = height * self .scaling_factor
9291
9392 try :
9493 x_vals = np .arange (width )
94+ if self .ui .pixera_radioButton .isChecked ():
95+ x_vals = x_vals * self .scaling_factor
9596 self .imv .setImage (image_array , xvals = x_vals )
96-
9797 roi_height = self .scaling_factor * height
98- self .roi .setPos ((0 ,height - roi_height ))
98+ self .roi .setPos ((0 , 0 ))
9999 self .roi .setSize ([width , roi_height ])
100-
101100 scale = pg .ScaleBar (size = 1 ,suffix = 'um' )
102101 scale .setParentItem (self .imv .view )
103102 scale .anchor ((1 , 1 ), (1 , 1 ), offset = (- 30 , - 30 ))
@@ -117,27 +116,29 @@ def line_profile_update_plot(self):
117116 if data is None :
118117 return
119118
120- x_values = coords [1 ][0 ]
121-
122- #calculate sums along columns in region
119+ x_values = coords [0 ,:,0 ]
120+ if self .ui .pixera_radioButton .isChecked ():
121+ x_values = x_values * self .scaling_factor
122+
123+ #calculate average along columns in region
123124 if len (data .shape ) == 2 : #if grayscale, average intensities
124- sums_to_plot = np .mean (data , axis = 0 )
125+ avg_to_plot = np .mean (data , axis = - 1 )
125126 try :
126- self .roi_plot .plot (x_values , sums_to_plot )
127+ self .roi_plot .plot (x_values , avg_to_plot )
127128 except :
128129 pass
129130 elif len (data .shape ) > 2 : #if rgb arrays, plot individual components
130131 r_values = data [:,:,0 ]
131132 g_values = data [:,:,1 ]
132133 b_values = data [:,:,2 ]
133- r_avg = np .mean (r_values , axis = 0 ) #average red values across columns
134- g_avg = np .mean (g_values , axis = 0 ) #average green values
135- b_avg = np .mean (b_values , axis = 0 ) #average blue values
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
136137 try :
137138 self .roi_plot .plot (x_values , r_avg , pen = 'r' )
138139 self .roi_plot .plot (x_values , g_avg , pen = 'g' )
139140 self .roi_plot .plot (x_values , b_avg , pen = 'b' )
140- except :
141+ except Exception as e :
141142 pass
142143
143144 def update_scaling_factor (self ):
@@ -164,10 +165,11 @@ def update_camera(self):
164165 if self .ui .spot_radioButton .isChecked ():
165166 self .camera_pixel_size = 7.4
166167 self .ui .greyscale_checkBox .setChecked (False )
168+ self .update_scaling_factor ()
167169 elif self .ui .pixera_radioButton .isChecked ():
168170 self .camera_pixel_size = 3
169171 self .ui .greyscale_checkBox .setChecked (True )
170-
172+ self . update_scaling_factor ()
171173 def close_application (self ):
172174 choice = QtGui .QMessageBox .question (self , 'EXIT!' ,
173175 "Do you want to exit the app?" ,
0 commit comments