@@ -35,17 +35,19 @@ def __init__(self):
3535 self .roi = self .imv .roi
3636 self .roi .translateSnap = True
3737 self .roi .scaleSnap = True
38- self .calc_scaling_factor () #initialize scaling_factor
39- self .roi .snapSize = self .scaling_factor #roi snaps to multiples of scaling_factor
40- self .roi .sigRegionChanged .connect (self .line_profile_update_plot )
38+ self .update_scaling_factor () #initialize scaling_factor
39+
4140 self .roi_plot = self .imv .getRoiPlot ().getPlotItem ()
4241
4342 self .ui .image_groupBox .layout ().addWidget (self .imv )
4443
4544 #set up ui signals
45+ self .roi .sigRegionChanged .connect (self .line_profile_update_plot )
4646 self .ui .load_image_pushButton .clicked .connect (self .load_image )
4747 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 )
4849
50+ self .num_plots = 0
4951 self .show ()
5052
5153 def load_image (self ):
@@ -54,28 +56,30 @@ def load_image(self):
5456 """
5557 try :
5658 file = QtWidgets .QFileDialog .getOpenFileName (self , 'Open file' , os .getcwd ())
57- image = Image .open (file [0 ])
58- image = image .rotate (- 90 , expand = True )
59- image_array = np .asarray (image )
60- try :
61- width = image_array .shape [0 ]
62- height = image_array .shape [1 ]
63- x_vals = np .arange (width )
64- self .imv .setImage (img = image_array , xvals = x_vals )
65- self .calc_scaling_factor ()
66- self .roi .setPos ((0 ,0 ))
67- self .roi .setSize ([width , height * self .scaling_factor ]) #set line roi
68- self .line_profile_update_plot ()
69- except :
70- pass
59+ self .original_image = Image .open (file [0 ])
60+ self .original_image = self .original_image .rotate (- 90 , expand = True )
61+ self .resize_to_scaling_factor (self .original_image )
7162 except Exception as err :
7263 print (format (err ))
7364
65+ def resize_to_scaling_factor (self , image ):
66+ image = image .resize ((round (image .size [0 ]* self .scaling_factor ), round (image .size [1 ]* self .scaling_factor )))
67+ image_array = np .asarray (image )
68+ width = image_array .shape [0 ]
69+ height = image_array .shape [1 ]
70+ try :
71+ x_vals = np .arange (width )
72+ self .imv .setImage (img = image_array , xvals = x_vals )
73+ self .roi .setPos ((0 ,0 ))
74+ self .roi .setSize ([width , height * self .scaling_factor ]) #set line roi
75+ self .line_profile_update_plot ()
76+ except :
77+ pass
78+
79+
7480 def line_profile_update_plot (self ):
7581 """ Handle line profile for intensity sum viewbox """
76- #if hasattr(self, "intensity_sums"):
7782 self .roi_plot .clear ()
78-
7983 image = self .imv .getProcessedImage ()
8084
8185 # Extract image data from ROI
@@ -84,8 +88,7 @@ def line_profile_update_plot(self):
8488 if data is None :
8589 return
8690
87- self .calc_scaling_factor ()
88- x_values = coords [1 ][0 ] * self .scaling_factor #adjust x-axis roi plot
91+ x_values = coords [1 ][0 ]
8992
9093 #calculate sums along columns in region
9194 if len (data .shape ) == 2 : #if grayscale, average intensities
@@ -108,7 +111,7 @@ def line_profile_update_plot(self):
108111 except :
109112 pass
110113
111- def calc_scaling_factor (self ):
114+ def update_scaling_factor (self ):
112115 """
113116 Calculate scaling factor
114117 """
@@ -117,6 +120,9 @@ def calc_scaling_factor(self):
117120 else :
118121 pixel_size = 7.4
119122 self .scaling_factor = pixel_size / int (self .ui .magnification_comboBox .currentText ())
123+ self .roi .snapSize = self .scaling_factor
124+ if hasattr (self , "original_image" ):
125+ self .resize_to_scaling_factor (self .original_image )
120126
121127 def switch_custom_pixel_size (self ):
122128 checked = self .ui .custom_pixel_size_checkBox .isChecked ()
0 commit comments