10
10
# local modules
11
11
12
12
pg .mkQApp ()
13
- pg .setConfigOption ('imageAxisOrder' , 'row -major' )
13
+ pg .setConfigOption ('imageAxisOrder' , 'col -major' )
14
14
15
15
base_path = Path (__file__ ).parent
16
16
file_path = (base_path / "image_analysis_gui.ui" ).resolve ()
@@ -36,11 +36,13 @@ def __init__(self):
36
36
self .imv = pg .ImageView ()
37
37
self .imv .getView ().setAspectLocked (lock = False , ratio = 1 )
38
38
self .imv .getView ().setMouseEnabled (x = True , y = True )
39
- # self.imv.getView().invertY(False)
39
+ self .imv .getView ().invertY (False )
40
40
self .roi = self .imv .roi
41
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
46
self .update_camera () #initialize camera pixel size
45
47
self .update_scaling_factor () #initialize scaling_factor
46
48
@@ -53,17 +55,19 @@ def __init__(self):
53
55
self .ui .custom_pixel_size_checkBox .stateChanged .connect (self .switch_custom_pixel_size )
54
56
self .ui .update_scaling_factor_pushButton .clicked .connect (self .reload_image )
55
57
self .ui .spot_radioButton .toggled .connect (self .update_camera )
58
+ self .ui .custom_pixel_size_spinBox .valueChanged .connect (self .update_scaling_factor )
56
59
57
60
self .show ()
58
61
62
+ #row major. invert y false, rotate false
59
63
def load_image (self ):
60
64
"""
61
65
Prompts the user to select a text file containing image data.
62
66
"""
63
67
try :
64
68
file = QtWidgets .QFileDialog .getOpenFileName (self , 'Open file' , os .getcwd ())
65
69
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
67
71
self .resize_to_scaling_factor (self .original_image )
68
72
except Exception as err :
69
73
print (format (err ))
@@ -72,8 +76,6 @@ def resize_to_scaling_factor(self, image):
72
76
"""
73
77
Handles loading of image according to scaling_factor
74
78
"""
75
- self .update_camera () #initialize camera pixel size
76
- self .update_scaling_factor () #initialize scaling_factor
77
79
78
80
if self .ui .pixera_radioButton .isChecked ():
79
81
image = self .original_image
@@ -86,18 +88,15 @@ def resize_to_scaling_factor(self, image):
86
88
image_array = np .array (image )
87
89
width = image_array .shape [0 ]
88
90
height = image_array .shape [1 ]
89
- if self .ui .pixera_radioButton .isChecked ():
90
- width = width * self .scaling_factor
91
- height = height * self .scaling_factor
92
91
93
92
try :
94
93
x_vals = np .arange (width )
94
+ if self .ui .pixera_radioButton .isChecked ():
95
+ x_vals = x_vals * self .scaling_factor
95
96
self .imv .setImage (image_array , xvals = x_vals )
96
-
97
97
roi_height = self .scaling_factor * height
98
- self .roi .setPos ((0 ,height - roi_height ))
98
+ self .roi .setPos ((0 , 0 ))
99
99
self .roi .setSize ([width , roi_height ])
100
-
101
100
scale = pg .ScaleBar (size = 1 ,suffix = 'um' )
102
101
scale .setParentItem (self .imv .view )
103
102
scale .anchor ((1 , 1 ), (1 , 1 ), offset = (- 30 , - 30 ))
@@ -117,27 +116,29 @@ def line_profile_update_plot(self):
117
116
if data is None :
118
117
return
119
118
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
123
124
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 )
125
126
try :
126
- self .roi_plot .plot (x_values , sums_to_plot )
127
+ self .roi_plot .plot (x_values , avg_to_plot )
127
128
except :
128
129
pass
129
130
elif len (data .shape ) > 2 : #if rgb arrays, plot individual components
130
131
r_values = data [:,:,0 ]
131
132
g_values = data [:,:,1 ]
132
133
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
136
137
try :
137
138
self .roi_plot .plot (x_values , r_avg , pen = 'r' )
138
139
self .roi_plot .plot (x_values , g_avg , pen = 'g' )
139
140
self .roi_plot .plot (x_values , b_avg , pen = 'b' )
140
- except :
141
+ except Exception as e :
141
142
pass
142
143
143
144
def update_scaling_factor (self ):
@@ -164,10 +165,11 @@ def update_camera(self):
164
165
if self .ui .spot_radioButton .isChecked ():
165
166
self .camera_pixel_size = 7.4
166
167
self .ui .greyscale_checkBox .setChecked (False )
168
+ self .update_scaling_factor ()
167
169
elif self .ui .pixera_radioButton .isChecked ():
168
170
self .camera_pixel_size = 3
169
171
self .ui .greyscale_checkBox .setChecked (True )
170
-
172
+ self . update_scaling_factor ()
171
173
def close_application (self ):
172
174
choice = QtGui .QMessageBox .question (self , 'EXIT!' ,
173
175
"Do you want to exit the app?" ,
0 commit comments