1010# local modules
1111
1212pg .mkQApp ()
13+ pg .setConfigOption ('imageAxisOrder' , 'col-major' )
1314
1415base_path = Path (__file__ ).parent
1516file_path = (base_path / "image_analysis_gui.ui" ).resolve ()
1819
1920WindowTemplate , TemplateBaseClass = pg .Qt .loadUiType (uiFile )
2021
22+ def updateDelay (scale , time ):
23+ """ Hack fix for scalebar inaccuracy"""
24+ QtCore .QTimer .singleShot (time , scale .updateBar )
25+
2126class MainWindow (TemplateBaseClass ):
2227
2328 def __init__ (self ):
@@ -45,10 +50,9 @@ def __init__(self):
4550 self .roi .sigRegionChanged .connect (self .line_profile_update_plot )
4651 self .ui .load_image_pushButton .clicked .connect (self .load_image )
4752 self .ui .custom_pixel_size_checkBox .stateChanged .connect (self .switch_custom_pixel_size )
48- self .ui .update_scaling_factor_pushButton .clicked .connect (self .update_scaling_factor )
53+ self .ui .update_scaling_factor_pushButton .clicked .connect (self .reload_image )
4954 self .ui .spot_radioButton .toggled .connect (self .update_camera )
5055
51- self .num_plots = 0
5256 self .show ()
5357
5458 def load_image (self ):
@@ -58,7 +62,7 @@ def load_image(self):
5862 try :
5963 file = QtWidgets .QFileDialog .getOpenFileName (self , 'Open file' , os .getcwd ())
6064 self .original_image = Image .open (file [0 ])
61- # self.original_image = self.original_image.rotate(-90, expand=True)
65+ self .original_image = self .original_image .rotate (- 90 , expand = True )
6266 self .resize_to_scaling_factor (self .original_image )
6367 except Exception as err :
6468 print (format (err ))
@@ -67,17 +71,25 @@ def resize_to_scaling_factor(self, image):
6771 """
6872 Handles loading of image according to scaling_factor
6973 """
74+ self .update_camera () #initialize camera pixel size
75+ self .update_scaling_factor () #initialize scaling_factor
7076 image = image .resize ((round (image .size [0 ]* self .scaling_factor ), round (image .size [1 ]* self .scaling_factor )))
7177 if self .ui .greyscale_checkBox .isChecked ():
7278 image = image .convert ("L" ) #convert to greyscale
73- image_array = np .asarray (image ).T #correct numpy array auto-flip
79+ image_array = np .array (image ) #correct numpy array auto-flip
80+
7481 width = image_array .shape [0 ]
7582 height = image_array .shape [1 ]
7683 try :
7784 x_vals = np .arange (width ) #imv x-axis
78- self .imv .setImage (img = image_array , xvals = x_vals )
85+ self .imv .setImage (image_array , xvals = x_vals )
7986 self .roi .setPos ((0 ,0 ))
80- self .roi .setSize ([width , height * self .scaling_factor ]) #set line roi
87+ self .roi .setSize ([width , self .camera_pixel_size ])
88+
89+ scale = pg .ScaleBar (size = 1 ,suffix = 'um' )
90+ scale .setParentItem (self .imv .view )
91+ scale .anchor ((1 , 1 ), (1 , 1 ), offset = (- 30 , - 30 ))
92+ self .imv .view .sigRangeChanged .connect (lambda : updateDelay (scale , 10 ))
8193 self .line_profile_update_plot ()
8294 except :
8395 pass
@@ -121,10 +133,13 @@ def update_scaling_factor(self):
121133 Calculate scaling factor
122134 """
123135 if self .ui .custom_pixel_size_checkBox .isChecked ():
124- self .scaling_factor = self .ui .custom_pixel_size_spinBox .value ()
136+ self .camera_pixel_size = self .ui .custom_pixel_size_spinBox .value ()
137+ self .scaling_factor = self .camera_pixel_size
125138 else :
126139 self .scaling_factor = self .camera_pixel_size / int (self .ui .magnification_comboBox .currentText ())
127140 self .roi .snapSize = self .scaling_factor #roi snaps to multiples of scaling_factor
141+
142+ def reload_image (self ):
128143 if hasattr (self , "original_image" ):
129144 self .resize_to_scaling_factor (self .original_image ) #resize image, sets up roi
130145
0 commit comments