10
10
# local modules
11
11
12
12
pg .mkQApp ()
13
+ pg .setConfigOption ('imageAxisOrder' , 'col-major' )
13
14
14
15
base_path = Path (__file__ ).parent
15
16
file_path = (base_path / "image_analysis_gui.ui" ).resolve ()
18
19
19
20
WindowTemplate , TemplateBaseClass = pg .Qt .loadUiType (uiFile )
20
21
22
+ def updateDelay (scale , time ):
23
+ """ Hack fix for scalebar inaccuracy"""
24
+ QtCore .QTimer .singleShot (time , scale .updateBar )
25
+
21
26
class MainWindow (TemplateBaseClass ):
22
27
23
28
def __init__ (self ):
@@ -45,10 +50,9 @@ def __init__(self):
45
50
self .roi .sigRegionChanged .connect (self .line_profile_update_plot )
46
51
self .ui .load_image_pushButton .clicked .connect (self .load_image )
47
52
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 )
49
54
self .ui .spot_radioButton .toggled .connect (self .update_camera )
50
55
51
- self .num_plots = 0
52
56
self .show ()
53
57
54
58
def load_image (self ):
@@ -58,7 +62,7 @@ def load_image(self):
58
62
try :
59
63
file = QtWidgets .QFileDialog .getOpenFileName (self , 'Open file' , os .getcwd ())
60
64
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 )
62
66
self .resize_to_scaling_factor (self .original_image )
63
67
except Exception as err :
64
68
print (format (err ))
@@ -67,17 +71,25 @@ def resize_to_scaling_factor(self, image):
67
71
"""
68
72
Handles loading of image according to scaling_factor
69
73
"""
74
+ self .update_camera () #initialize camera pixel size
75
+ self .update_scaling_factor () #initialize scaling_factor
70
76
image = image .resize ((round (image .size [0 ]* self .scaling_factor ), round (image .size [1 ]* self .scaling_factor )))
71
77
if self .ui .greyscale_checkBox .isChecked ():
72
78
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
+
74
81
width = image_array .shape [0 ]
75
82
height = image_array .shape [1 ]
76
83
try :
77
84
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 )
79
86
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 ))
81
93
self .line_profile_update_plot ()
82
94
except :
83
95
pass
@@ -121,10 +133,13 @@ def update_scaling_factor(self):
121
133
Calculate scaling factor
122
134
"""
123
135
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
125
138
else :
126
139
self .scaling_factor = self .camera_pixel_size / int (self .ui .magnification_comboBox .currentText ())
127
140
self .roi .snapSize = self .scaling_factor #roi snaps to multiples of scaling_factor
141
+
142
+ def reload_image (self ):
128
143
if hasattr (self , "original_image" ):
129
144
self .resize_to_scaling_factor (self .original_image ) #resize image, sets up roi
130
145
0 commit comments