nanopyx.methods.esrrf.parameter_sweep
1import numpy as np 2from matplotlib import pyplot as plt 3from ...core.analysis.parameter_sweep import ParameterSweep 4 5 6def run_esrrf_parameter_sweep( 7 img: np.ndarray, 8 magnification: int = 2, 9 sensitivities: list = [1, 2], 10 radii: list = [1, 1.5], 11 temporal_correlation: str = "AVG", 12 use_decorr: bool = False, 13 plot_sweep=False, 14 return_qnr=False, 15 n_frames=None, 16): 17 """ 18 Conducts a parameter sweep for enhanced Super-Resolution Radial Fluctuations (eSRRF) analysis on an image. 19 20 Parameters 21 ---------- 22 img : np.ndarray 23 The input image as a 2D numpy array. 24 magnification : int, optional 25 The magnification factor to be applied during the ESRRF analysis. Default is 2. 26 sensitivities : list of int, optional 27 A list of sensitivity values to be used in the parameter sweep. Default is [1, 2]. 28 radii : list of float, optional 29 A list of radii values to be used in the parameter sweep. Default is [1, 1.5]. 30 temporal_correlation : str, optional 31 The method of temporal correlation to be used. Default is "AVG". 32 return_qnr : bool, optional 33 If True, return an array with QnR value for each combination of sensitivities and radii. 34 If False, return a tuple of optimal sensitivity and radius values. 35 n_frames : int, optional 36 if None, uses all frames, otherwise splits the data into batches with size = n_frames. 37 38 39 Returns 40 ------- 41 np.ndarray or tuple 42 If return_qnr is True, returns an array with QnR value for each combination of sensitivities and radii. Indices of dimension 0 corresponds to indices of sensitivities list and dimension 1 to radii list. 43 Suggestion: sensitivity_index, radius_index = np.argmax(run_esrrf_parameter_sweep()) 44 Optimal parameters will then correspond to: sensitivities[sensitivity_index] and radii[radius_index] 45 If return_qnr is False, returns a tuple of optimal sensitivity and radius values. 46 47 Notes 48 ----- 49 This function performs a parameter sweep for the ESRRF method, which is used for super-resolution imaging analysis. It varies sensitivity and radius to find optimal settings for image enhancement. 50 """ 51 ps = ParameterSweep() 52 out = ps.run( 53 img, 54 magnification, 55 sensitivity_array=sensitivities, 56 radius_array=radii, 57 temporal_correlation=temporal_correlation, 58 use_decorr=use_decorr, 59 n_frames=n_frames 60 ) 61 62 if plot_sweep: 63 fig, ax = plt.subplots() 64 ax.imshow(out, cmap="plasma") 65 ax.set_xticks(np.arange(len(radii)), labels=radii) 66 ax.set_yticks(np.arange(len(sensitivities)), labels=sensitivities) 67 print(range(len(sensitivities)), range(len(radii))) 68 for i in range(len(sensitivities)): 69 for j in range(len(radii)): 70 ax.text(j, i, round(out[i, j], 2), ha="center", va="center", color="w") 71 ax.set_title("Parameter Sweep QnR") 72 ax.set_xlabel("Radii") 73 ax.set_ylabel("Sensitivities") 74 fig.tight_layout() 75 plt.show() 76 77 if return_qnr: 78 return out 79 else: 80 sens_idx, rad_idx = np.unravel_index(np.argmax(out), out.shape) 81 return sensitivities[sens_idx], radii[rad_idx]
7def run_esrrf_parameter_sweep( 8 img: np.ndarray, 9 magnification: int = 2, 10 sensitivities: list = [1, 2], 11 radii: list = [1, 1.5], 12 temporal_correlation: str = "AVG", 13 use_decorr: bool = False, 14 plot_sweep=False, 15 return_qnr=False, 16 n_frames=None, 17): 18 """ 19 Conducts a parameter sweep for enhanced Super-Resolution Radial Fluctuations (eSRRF) analysis on an image. 20 21 Parameters 22 ---------- 23 img : np.ndarray 24 The input image as a 2D numpy array. 25 magnification : int, optional 26 The magnification factor to be applied during the ESRRF analysis. Default is 2. 27 sensitivities : list of int, optional 28 A list of sensitivity values to be used in the parameter sweep. Default is [1, 2]. 29 radii : list of float, optional 30 A list of radii values to be used in the parameter sweep. Default is [1, 1.5]. 31 temporal_correlation : str, optional 32 The method of temporal correlation to be used. Default is "AVG". 33 return_qnr : bool, optional 34 If True, return an array with QnR value for each combination of sensitivities and radii. 35 If False, return a tuple of optimal sensitivity and radius values. 36 n_frames : int, optional 37 if None, uses all frames, otherwise splits the data into batches with size = n_frames. 38 39 40 Returns 41 ------- 42 np.ndarray or tuple 43 If return_qnr is True, returns an array with QnR value for each combination of sensitivities and radii. Indices of dimension 0 corresponds to indices of sensitivities list and dimension 1 to radii list. 44 Suggestion: sensitivity_index, radius_index = np.argmax(run_esrrf_parameter_sweep()) 45 Optimal parameters will then correspond to: sensitivities[sensitivity_index] and radii[radius_index] 46 If return_qnr is False, returns a tuple of optimal sensitivity and radius values. 47 48 Notes 49 ----- 50 This function performs a parameter sweep for the ESRRF method, which is used for super-resolution imaging analysis. It varies sensitivity and radius to find optimal settings for image enhancement. 51 """ 52 ps = ParameterSweep() 53 out = ps.run( 54 img, 55 magnification, 56 sensitivity_array=sensitivities, 57 radius_array=radii, 58 temporal_correlation=temporal_correlation, 59 use_decorr=use_decorr, 60 n_frames=n_frames 61 ) 62 63 if plot_sweep: 64 fig, ax = plt.subplots() 65 ax.imshow(out, cmap="plasma") 66 ax.set_xticks(np.arange(len(radii)), labels=radii) 67 ax.set_yticks(np.arange(len(sensitivities)), labels=sensitivities) 68 print(range(len(sensitivities)), range(len(radii))) 69 for i in range(len(sensitivities)): 70 for j in range(len(radii)): 71 ax.text(j, i, round(out[i, j], 2), ha="center", va="center", color="w") 72 ax.set_title("Parameter Sweep QnR") 73 ax.set_xlabel("Radii") 74 ax.set_ylabel("Sensitivities") 75 fig.tight_layout() 76 plt.show() 77 78 if return_qnr: 79 return out 80 else: 81 sens_idx, rad_idx = np.unravel_index(np.argmax(out), out.shape) 82 return sensitivities[sens_idx], radii[rad_idx]
Conducts a parameter sweep for enhanced Super-Resolution Radial Fluctuations (eSRRF) analysis on an image.
Parameters
img : np.ndarray The input image as a 2D numpy array. magnification : int, optional The magnification factor to be applied during the ESRRF analysis. Default is 2. sensitivities : list of int, optional A list of sensitivity values to be used in the parameter sweep. Default is [1, 2]. radii : list of float, optional A list of radii values to be used in the parameter sweep. Default is [1, 1.5]. temporal_correlation : str, optional The method of temporal correlation to be used. Default is "AVG". return_qnr : bool, optional If True, return an array with QnR value for each combination of sensitivities and radii. If False, return a tuple of optimal sensitivity and radius values. n_frames : int, optional if None, uses all frames, otherwise splits the data into batches with size = n_frames.
Returns
np.ndarray or tuple If return_qnr is True, returns an array with QnR value for each combination of sensitivities and radii. Indices of dimension 0 corresponds to indices of sensitivities list and dimension 1 to radii list. Suggestion: sensitivity_index, radius_index = np.argmax(run_esrrf_parameter_sweep()) Optimal parameters will then correspond to: sensitivities[sensitivity_index] and radii[radius_index] If return_qnr is False, returns a tuple of optimal sensitivity and radius values.
Notes
This function performs a parameter sweep for the ESRRF method, which is used for super-resolution imaging analysis. It varies sensitivity and radius to find optimal settings for image enhancement.