nanopyx.core.utils.benchmark
1import math 2import nanopyx 3import numpy as np 4 5from ..generate.beads import ( 6 generate_channel_misalignment, 7 generate_timelapse_drift, 8) 9 10 11def benchmark_all_le_methods( 12 n_benchmark_runs=3, 13 img_dims=100, 14 shift=1, 15 magnification=2, 16 rotation=math.radians(15), 17 conv_kernel_dims=5, 18): 19 """ 20 Runs benchmark tests for all LE methods. 21 Args: 22 n_benchmark_runs (int): The number of benchmark runs to perform. Default is 3. 23 img_dims (int): The dimensions of the input image. Default is 100. 24 shift (int): The amount of shift to apply to the image during benchmarking. Default is 2. 25 magnification (int): The magnification factor to apply to the image during benchmarking. Default is 5. 26 rotation (float): The rotation angle to apply to the image during benchmarking. Default is 0.2617993877991494 (equal to 15 degrees in radians). 27 conv_kernel_dims (int): The dimensions of the convolution kernel to use during benchmarking. Default is 23. 28 Returns: 29 None 30 """ 31 32 img = np.random.random((img_dims, img_dims)).astype(np.float32) 33 img_int = np.random.random( 34 (img_dims * magnification, img_dims * magnification) 35 ).astype(np.float32) 36 kernel = np.ones((conv_kernel_dims, conv_kernel_dims)).astype(np.float32) 37 38 bicubic_sm = ( 39 nanopyx.core.transform._le_interpolation_bicubic.ShiftAndMagnify() 40 ) 41 bicubic_ssr = ( 42 nanopyx.core.transform._le_interpolation_bicubic.ShiftScaleRotate() 43 ) 44 cr_sm = ( 45 nanopyx.core.transform._le_interpolation_catmull_rom.ShiftAndMagnify() 46 ) 47 cr_ssr = ( 48 nanopyx.core.transform._le_interpolation_catmull_rom.ShiftScaleRotate() 49 ) 50 l_sm = nanopyx.core.transform._le_interpolation_lanczos.ShiftAndMagnify() 51 l_ssr = nanopyx.core.transform._le_interpolation_lanczos.ShiftScaleRotate() 52 nn_sm = ( 53 nanopyx.core.transform._le_interpolation_nearest_neighbor.ShiftAndMagnify() 54 ) 55 nn_ssr = ( 56 nanopyx.core.transform._le_interpolation_nearest_neighbor.ShiftScaleRotate() 57 ) 58 nn_pt = ( 59 nanopyx.core.transform._le_interpolation_nearest_neighbor.PolarTransform() 60 ) 61 62 conv2d = nanopyx.core.transform._le_convolution.Convolution() 63 64 rad = nanopyx.core.transform._le_radiality.Radiality() 65 rc = ( 66 nanopyx.core.transform._le_roberts_cross_gradients.GradientRobertsCross() 67 ) 68 rgc = ( 69 nanopyx.core.transform._le_radial_gradient_convergence.RadialGradientConvergence() 70 ) 71 72 esrrf = nanopyx.core.transform._le_esrrf.eSRRF() 73 esrrf3d = nanopyx.core.transform._le_esrrf3d.eSRRF3D() 74 75 nlm = nanopyx.core.transform._le_nlm_denoising.NLMDenoising() 76 77 for i in range(n_benchmark_runs): 78 bicubic_sm.benchmark(img, shift, shift, magnification, magnification) 79 for i in range(n_benchmark_runs): 80 cr_sm.benchmark(img, shift, shift, magnification, magnification) 81 for i in range(n_benchmark_runs): 82 l_sm.benchmark(img, shift, shift, magnification, magnification) 83 for i in range(n_benchmark_runs): 84 nn_sm.benchmark(img, shift, shift, magnification, magnification) 85 86 for i in range(n_benchmark_runs): 87 bicubic_ssr.benchmark( 88 img, shift, shift, magnification, magnification, rotation 89 ) 90 for i in range(n_benchmark_runs): 91 cr_ssr.benchmark( 92 img, shift, shift, magnification, magnification, rotation 93 ) 94 for i in range(n_benchmark_runs): 95 l_ssr.benchmark( 96 img, shift, shift, magnification, magnification, rotation 97 ) 98 for i in range(n_benchmark_runs): 99 nn_ssr.benchmark( 100 img, shift, shift, magnification, magnification, rotation 101 ) 102 103 for i in range(n_benchmark_runs): 104 nn_pt.benchmark(img, (img_dims, img_dims), "log") 105 106 for i in range(n_benchmark_runs): 107 conv2d.benchmark(img, kernel) 108 109 for i in range(n_benchmark_runs): 110 rad.benchmark(img, img_int) 111 for i in range(n_benchmark_runs): 112 rc.benchmark(img) 113 for i in range(n_benchmark_runs): 114 rgc.benchmark(img_int, img_int, img_int) 115 116 for i in range(n_benchmark_runs): 117 esrrf.benchmark(img) 118 119 for i in range(n_benchmark_runs): 120 esrrf3d.benchmark(img[np.newaxis, ...]) 121 122 for i in range(n_benchmark_runs): 123 nlm.benchmark(img) 124 125 channel_reg = ( 126 nanopyx.core.analysis._le_channel_registration.ChannelRegistrationEstimator() 127 ) 128 129 drift_reg = nanopyx.core.analysis._le_drift_calculator.DriftEstimator() 130 131 channels_img = generate_channel_misalignment().astype(np.float32) 132 drift_img = generate_timelapse_drift().astype(np.float32) 133 134 for i in range(n_benchmark_runs): 135 channel_reg.benchmark(channels_img, 0, 10, 3, 0.5) 136 137 for i in range(n_benchmark_runs): 138 drift_reg.benchmark(drift_img)
def
benchmark_all_le_methods( n_benchmark_runs=3, img_dims=100, shift=1, magnification=2, rotation=0.2617993877991494, conv_kernel_dims=5):
12def benchmark_all_le_methods( 13 n_benchmark_runs=3, 14 img_dims=100, 15 shift=1, 16 magnification=2, 17 rotation=math.radians(15), 18 conv_kernel_dims=5, 19): 20 """ 21 Runs benchmark tests for all LE methods. 22 Args: 23 n_benchmark_runs (int): The number of benchmark runs to perform. Default is 3. 24 img_dims (int): The dimensions of the input image. Default is 100. 25 shift (int): The amount of shift to apply to the image during benchmarking. Default is 2. 26 magnification (int): The magnification factor to apply to the image during benchmarking. Default is 5. 27 rotation (float): The rotation angle to apply to the image during benchmarking. Default is 0.2617993877991494 (equal to 15 degrees in radians). 28 conv_kernel_dims (int): The dimensions of the convolution kernel to use during benchmarking. Default is 23. 29 Returns: 30 None 31 """ 32 33 img = np.random.random((img_dims, img_dims)).astype(np.float32) 34 img_int = np.random.random( 35 (img_dims * magnification, img_dims * magnification) 36 ).astype(np.float32) 37 kernel = np.ones((conv_kernel_dims, conv_kernel_dims)).astype(np.float32) 38 39 bicubic_sm = ( 40 nanopyx.core.transform._le_interpolation_bicubic.ShiftAndMagnify() 41 ) 42 bicubic_ssr = ( 43 nanopyx.core.transform._le_interpolation_bicubic.ShiftScaleRotate() 44 ) 45 cr_sm = ( 46 nanopyx.core.transform._le_interpolation_catmull_rom.ShiftAndMagnify() 47 ) 48 cr_ssr = ( 49 nanopyx.core.transform._le_interpolation_catmull_rom.ShiftScaleRotate() 50 ) 51 l_sm = nanopyx.core.transform._le_interpolation_lanczos.ShiftAndMagnify() 52 l_ssr = nanopyx.core.transform._le_interpolation_lanczos.ShiftScaleRotate() 53 nn_sm = ( 54 nanopyx.core.transform._le_interpolation_nearest_neighbor.ShiftAndMagnify() 55 ) 56 nn_ssr = ( 57 nanopyx.core.transform._le_interpolation_nearest_neighbor.ShiftScaleRotate() 58 ) 59 nn_pt = ( 60 nanopyx.core.transform._le_interpolation_nearest_neighbor.PolarTransform() 61 ) 62 63 conv2d = nanopyx.core.transform._le_convolution.Convolution() 64 65 rad = nanopyx.core.transform._le_radiality.Radiality() 66 rc = ( 67 nanopyx.core.transform._le_roberts_cross_gradients.GradientRobertsCross() 68 ) 69 rgc = ( 70 nanopyx.core.transform._le_radial_gradient_convergence.RadialGradientConvergence() 71 ) 72 73 esrrf = nanopyx.core.transform._le_esrrf.eSRRF() 74 esrrf3d = nanopyx.core.transform._le_esrrf3d.eSRRF3D() 75 76 nlm = nanopyx.core.transform._le_nlm_denoising.NLMDenoising() 77 78 for i in range(n_benchmark_runs): 79 bicubic_sm.benchmark(img, shift, shift, magnification, magnification) 80 for i in range(n_benchmark_runs): 81 cr_sm.benchmark(img, shift, shift, magnification, magnification) 82 for i in range(n_benchmark_runs): 83 l_sm.benchmark(img, shift, shift, magnification, magnification) 84 for i in range(n_benchmark_runs): 85 nn_sm.benchmark(img, shift, shift, magnification, magnification) 86 87 for i in range(n_benchmark_runs): 88 bicubic_ssr.benchmark( 89 img, shift, shift, magnification, magnification, rotation 90 ) 91 for i in range(n_benchmark_runs): 92 cr_ssr.benchmark( 93 img, shift, shift, magnification, magnification, rotation 94 ) 95 for i in range(n_benchmark_runs): 96 l_ssr.benchmark( 97 img, shift, shift, magnification, magnification, rotation 98 ) 99 for i in range(n_benchmark_runs): 100 nn_ssr.benchmark( 101 img, shift, shift, magnification, magnification, rotation 102 ) 103 104 for i in range(n_benchmark_runs): 105 nn_pt.benchmark(img, (img_dims, img_dims), "log") 106 107 for i in range(n_benchmark_runs): 108 conv2d.benchmark(img, kernel) 109 110 for i in range(n_benchmark_runs): 111 rad.benchmark(img, img_int) 112 for i in range(n_benchmark_runs): 113 rc.benchmark(img) 114 for i in range(n_benchmark_runs): 115 rgc.benchmark(img_int, img_int, img_int) 116 117 for i in range(n_benchmark_runs): 118 esrrf.benchmark(img) 119 120 for i in range(n_benchmark_runs): 121 esrrf3d.benchmark(img[np.newaxis, ...]) 122 123 for i in range(n_benchmark_runs): 124 nlm.benchmark(img) 125 126 channel_reg = ( 127 nanopyx.core.analysis._le_channel_registration.ChannelRegistrationEstimator() 128 ) 129 130 drift_reg = nanopyx.core.analysis._le_drift_calculator.DriftEstimator() 131 132 channels_img = generate_channel_misalignment().astype(np.float32) 133 drift_img = generate_timelapse_drift().astype(np.float32) 134 135 for i in range(n_benchmark_runs): 136 channel_reg.benchmark(channels_img, 0, 10, 3, 0.5) 137 138 for i in range(n_benchmark_runs): 139 drift_reg.benchmark(drift_img)
Runs benchmark tests for all LE methods. Args: n_benchmark_runs (int): The number of benchmark runs to perform. Default is 3. img_dims (int): The dimensions of the input image. Default is 100. shift (int): The amount of shift to apply to the image during benchmarking. Default is 2. magnification (int): The magnification factor to apply to the image during benchmarking. Default is 5. rotation (float): The rotation angle to apply to the image during benchmarking. Default is 0.2617993877991494 (equal to 15 degrees in radians). conv_kernel_dims (int): The dimensions of the convolution kernel to use during benchmarking. Default is 23. Returns: None