nanopyx.core.utils.benchmark

 1import math
 2import nanopyx
 3import numpy as np
 4
 5from ..generate.beads import generate_channel_misalignment, generate_timelapse_drift
 6
 7def benchmark_all_le_methods(
 8    n_benchmark_runs=3, img_dims=100, shift=1, magnification=2, rotation=math.radians(15), conv_kernel_dims=5
 9):
10    """
11    Runs benchmark tests for all LE methods.
12    Args:
13        n_benchmark_runs (int): The number of benchmark runs to perform. Default is 3.
14        img_dims (int): The dimensions of the input image. Default is 100.
15        shift (int): The amount of shift to apply to the image during benchmarking. Default is 2.
16        magnification (int): The magnification factor to apply to the image during benchmarking. Default is 5.
17        rotation (float): The rotation angle to apply to the image during benchmarking. Default is 0.2617993877991494 (equal to 15 degrees in radians).
18        conv_kernel_dims (int): The dimensions of the convolution kernel to use during benchmarking. Default is 23.
19    Returns:
20        None
21    """
22
23    img = np.random.random((img_dims, img_dims)).astype(np.float32)
24    img_int = np.random.random((img_dims * magnification, img_dims * magnification)).astype(np.float32)
25    kernel = np.ones((conv_kernel_dims, conv_kernel_dims)).astype(np.float32)
26
27    bicubic_sm = nanopyx.core.transform._le_interpolation_bicubic.ShiftAndMagnify()
28    bicubic_ssr = nanopyx.core.transform._le_interpolation_bicubic.ShiftScaleRotate()
29    cr_sm = nanopyx.core.transform._le_interpolation_catmull_rom.ShiftAndMagnify()
30    cr_ssr = nanopyx.core.transform._le_interpolation_catmull_rom.ShiftScaleRotate()
31    l_sm = nanopyx.core.transform._le_interpolation_lanczos.ShiftAndMagnify()
32    l_ssr = nanopyx.core.transform._le_interpolation_lanczos.ShiftScaleRotate()
33    nn_sm = nanopyx.core.transform._le_interpolation_nearest_neighbor.ShiftAndMagnify()
34    nn_ssr = nanopyx.core.transform._le_interpolation_nearest_neighbor.ShiftScaleRotate()
35    nn_pt = nanopyx.core.transform._le_interpolation_nearest_neighbor.PolarTransform()
36
37    conv2d = nanopyx.core.transform._le_convolution.Convolution()
38
39    rad = nanopyx.core.transform._le_radiality.Radiality()
40    rc = nanopyx.core.transform._le_roberts_cross_gradients.GradientRobertsCross()
41    rgc = nanopyx.core.transform._le_radial_gradient_convergence.RadialGradientConvergence()
42
43    esrrf = nanopyx.core.transform._le_esrrf.eSRRF()
44
45    nlm = nanopyx.core.transform._le_nlm_denoising.NLMDenoising()
46
47    for i in range(n_benchmark_runs):
48        bicubic_sm.benchmark(img, shift, shift, magnification, magnification)
49    for i in range(n_benchmark_runs):
50        cr_sm.benchmark(img, shift, shift, magnification, magnification)
51    for i in range(n_benchmark_runs):
52        l_sm.benchmark(img, shift, shift, magnification, magnification)
53    for i in range(n_benchmark_runs):
54        nn_sm.benchmark(img, shift, shift, magnification, magnification)
55
56    for i in range(n_benchmark_runs):
57        bicubic_ssr.benchmark(img, shift, shift, magnification, magnification, rotation)
58    for i in range(n_benchmark_runs):
59        cr_ssr.benchmark(img, shift, shift, magnification, magnification, rotation)
60    for i in range(n_benchmark_runs):
61        l_ssr.benchmark(img, shift, shift, magnification, magnification, rotation)
62    for i in range(n_benchmark_runs):
63        nn_ssr.benchmark(img, shift, shift, magnification, magnification, rotation)
64
65    for i in range(n_benchmark_runs):
66        nn_pt.benchmark(img, (img_dims, img_dims), "log")
67
68    for i in range(n_benchmark_runs):
69        conv2d.benchmark(img, kernel)
70
71    for i in range(n_benchmark_runs):
72        rad.benchmark(img, img_int)
73    for i in range(n_benchmark_runs):
74        rc.benchmark(img)
75    for i in range(n_benchmark_runs):
76        rgc.benchmark(img_int, img_int, img_int)
77
78    for i in range(n_benchmark_runs):
79        esrrf.benchmark(img)
80
81    for i in range(n_benchmark_runs):
82        nlm.benchmark(img)
83
84    channel_reg = nanopyx.core.analysis._le_channel_registration.ChannelRegistrationEstimator()
85
86    drift_reg = nanopyx.core.analysis._le_drift_calculator.DriftEstimator()
87
88    channels_img = generate_channel_misalignment().astype(np.float32)
89    drift_img = generate_timelapse_drift().astype(np.float32)
90
91    for i in range(n_benchmark_runs):
92        channel_reg.benchmark(channels_img, 0, 10, 3, 0.5)
93
94    for i in range(n_benchmark_runs):
95        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):
 8def benchmark_all_le_methods(
 9    n_benchmark_runs=3, img_dims=100, shift=1, magnification=2, rotation=math.radians(15), conv_kernel_dims=5
10):
11    """
12    Runs benchmark tests for all LE methods.
13    Args:
14        n_benchmark_runs (int): The number of benchmark runs to perform. Default is 3.
15        img_dims (int): The dimensions of the input image. Default is 100.
16        shift (int): The amount of shift to apply to the image during benchmarking. Default is 2.
17        magnification (int): The magnification factor to apply to the image during benchmarking. Default is 5.
18        rotation (float): The rotation angle to apply to the image during benchmarking. Default is 0.2617993877991494 (equal to 15 degrees in radians).
19        conv_kernel_dims (int): The dimensions of the convolution kernel to use during benchmarking. Default is 23.
20    Returns:
21        None
22    """
23
24    img = np.random.random((img_dims, img_dims)).astype(np.float32)
25    img_int = np.random.random((img_dims * magnification, img_dims * magnification)).astype(np.float32)
26    kernel = np.ones((conv_kernel_dims, conv_kernel_dims)).astype(np.float32)
27
28    bicubic_sm = nanopyx.core.transform._le_interpolation_bicubic.ShiftAndMagnify()
29    bicubic_ssr = nanopyx.core.transform._le_interpolation_bicubic.ShiftScaleRotate()
30    cr_sm = nanopyx.core.transform._le_interpolation_catmull_rom.ShiftAndMagnify()
31    cr_ssr = nanopyx.core.transform._le_interpolation_catmull_rom.ShiftScaleRotate()
32    l_sm = nanopyx.core.transform._le_interpolation_lanczos.ShiftAndMagnify()
33    l_ssr = nanopyx.core.transform._le_interpolation_lanczos.ShiftScaleRotate()
34    nn_sm = nanopyx.core.transform._le_interpolation_nearest_neighbor.ShiftAndMagnify()
35    nn_ssr = nanopyx.core.transform._le_interpolation_nearest_neighbor.ShiftScaleRotate()
36    nn_pt = nanopyx.core.transform._le_interpolation_nearest_neighbor.PolarTransform()
37
38    conv2d = nanopyx.core.transform._le_convolution.Convolution()
39
40    rad = nanopyx.core.transform._le_radiality.Radiality()
41    rc = nanopyx.core.transform._le_roberts_cross_gradients.GradientRobertsCross()
42    rgc = nanopyx.core.transform._le_radial_gradient_convergence.RadialGradientConvergence()
43
44    esrrf = nanopyx.core.transform._le_esrrf.eSRRF()
45
46    nlm = nanopyx.core.transform._le_nlm_denoising.NLMDenoising()
47
48    for i in range(n_benchmark_runs):
49        bicubic_sm.benchmark(img, shift, shift, magnification, magnification)
50    for i in range(n_benchmark_runs):
51        cr_sm.benchmark(img, shift, shift, magnification, magnification)
52    for i in range(n_benchmark_runs):
53        l_sm.benchmark(img, shift, shift, magnification, magnification)
54    for i in range(n_benchmark_runs):
55        nn_sm.benchmark(img, shift, shift, magnification, magnification)
56
57    for i in range(n_benchmark_runs):
58        bicubic_ssr.benchmark(img, shift, shift, magnification, magnification, rotation)
59    for i in range(n_benchmark_runs):
60        cr_ssr.benchmark(img, shift, shift, magnification, magnification, rotation)
61    for i in range(n_benchmark_runs):
62        l_ssr.benchmark(img, shift, shift, magnification, magnification, rotation)
63    for i in range(n_benchmark_runs):
64        nn_ssr.benchmark(img, shift, shift, magnification, magnification, rotation)
65
66    for i in range(n_benchmark_runs):
67        nn_pt.benchmark(img, (img_dims, img_dims), "log")
68
69    for i in range(n_benchmark_runs):
70        conv2d.benchmark(img, kernel)
71
72    for i in range(n_benchmark_runs):
73        rad.benchmark(img, img_int)
74    for i in range(n_benchmark_runs):
75        rc.benchmark(img)
76    for i in range(n_benchmark_runs):
77        rgc.benchmark(img_int, img_int, img_int)
78
79    for i in range(n_benchmark_runs):
80        esrrf.benchmark(img)
81
82    for i in range(n_benchmark_runs):
83        nlm.benchmark(img)
84
85    channel_reg = nanopyx.core.analysis._le_channel_registration.ChannelRegistrationEstimator()
86
87    drift_reg = nanopyx.core.analysis._le_drift_calculator.DriftEstimator()
88
89    channels_img = generate_channel_misalignment().astype(np.float32)
90    drift_img = generate_timelapse_drift().astype(np.float32)
91
92    for i in range(n_benchmark_runs):
93        channel_reg.benchmark(channels_img, 0, 10, 3, 0.5)
94
95    for i in range(n_benchmark_runs):
96        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