nanopyx.methods.squirrel.resolution

  1import numpy as np
  2from matplotlib import pyplot as plt
  3from ...core.analysis.decorr import DecorrAnalysis
  4from ...core.analysis.frc import FIRECalculator
  5
  6
  7def calculate_frc(
  8    frame_1: np.ndarray, frame_2: np.ndarray, pixel_size: float = 1, units: str = "pixel", plot_frc_curve: bool = False
  9):
 10    """
 11    Calculate the Fourier Ring Correlation (FRC) between two images to estimate their resolution.
 12
 13    Parameters
 14    ----------
 15    frame_1 : np.ndarray
 16        The first image frame as a 2D numpy array.
 17    frame_2 : np.ndarray
 18        The second image frame as a 2D numpy array.
 19    pixel_size : float, optional
 20        The physical size of a pixel in the specified units. Default is 1.
 21    units : str, optional
 22        The units of measurement for the pixel size (e.g., "pixel", "nm", "um"). Default is "pixel".
 23    plot_frc_curve : bool, optional
 24        If True, plots the FRC curve. Default is False.
 25
 26    Returns
 27    -------
 28    float
 29        The resolution estimate based on the FRC calculation.
 30
 31    Notes
 32    -----
 33    The Fourier Ring Correlation (FRC) is a method to estimate the resolution of images, particularly useful in microscopy. It compares the similarity of two images in the frequency domain, providing a measure of their resolution.
 34    """
 35    frc_calc = FIRECalculator(pixel_size=pixel_size, units=units)
 36    res = frc_calc.calculate_fire_number(frame_1, frame_2)
 37
 38    if plot_frc_curve:
 39        plt.axis("off")
 40        plt.subplots_adjust(left=0, right=1, top=1, bottom=0, wspace=0, hspace=0)
 41        plt.imshow(frc_calc.plot_frc_curve())
 42        plt.show()
 43
 44    return res
 45
 46
 47def calculate_decorr_analysis(
 48    frame: np.ndarray,
 49    rmin: float = 0,
 50    rmax: float = 1,
 51    n_r: int = 50,
 52    n_g: int = 10,
 53    pixel_size: float = 1,
 54    units: str = "pixel",
 55    roi: tuple = (0, 0, 0, 0),
 56    plot_decorr_analysis=False,
 57):
 58    """
 59    Perform decorrelation analysis on a given image frame to estimate its resolution.
 60
 61    Parameters
 62    ----------
 63    frame : np.ndarray
 64        The image frame as a 2D numpy array.
 65    rmin : float, optional
 66        The minimum radius for decorrelation analysis. Default is 0.
 67    rmax : float, optional
 68        The maximum radius for decorrelation analysis. Default is 1.
 69    n_r : int, optional
 70        The number of radial divisions for analysis. Default is 50.
 71    n_g : int, optional
 72        The number of angular divisions for analysis. Default is 10.
 73    pixel_size : float, optional
 74        The physical size of a pixel in the specified units. Default is 1.
 75    units : str, optional
 76        The units of measurement for the pixel size (e.g., "pixel", "nm", "um"). Default is "pixel".
 77    roi : tuple, optional
 78        The region of interest in the format (x_min, y_min, x_max, y_max). Default is (0, 0, 0, 0).
 79    plot_decorr_analysis : bool, optional
 80        If True, plots the results of the decorrelation analysis. Default is False.
 81
 82    Returns
 83    -------
 84    float
 85        The resolution estimate based on the decorrelation analysis.
 86
 87    Notes
 88    -----
 89    Decorrelation analysis is a technique used to estimate the resolution of images by analyzing the decorrelation of intensity values over different spatial scales. It is particularly useful in microscopy and imaging where direct resolution measurement is challenging.
 90    """
 91    decorr_calc = DecorrAnalysis(pixel_size=pixel_size, units=units, rmin=rmin, rmax=rmax, n_r=n_r, n_g=n_g, roi=roi)
 92    decorr_calc.run_analysis(frame)
 93
 94    if plot_decorr_analysis:
 95        plt.axis("off")
 96        plt.subplots_adjust(left=0, right=1, top=1, bottom=0, wspace=0, hspace=0)
 97        plt.imshow(decorr_calc.plot_results())
 98        plt.show()
 99
100    return decorr_calc.resolution
def calculate_frc( frame_1: numpy.ndarray, frame_2: numpy.ndarray, pixel_size: float = 1, units: str = 'pixel', plot_frc_curve: bool = False):
 8def calculate_frc(
 9    frame_1: np.ndarray, frame_2: np.ndarray, pixel_size: float = 1, units: str = "pixel", plot_frc_curve: bool = False
10):
11    """
12    Calculate the Fourier Ring Correlation (FRC) between two images to estimate their resolution.
13
14    Parameters
15    ----------
16    frame_1 : np.ndarray
17        The first image frame as a 2D numpy array.
18    frame_2 : np.ndarray
19        The second image frame as a 2D numpy array.
20    pixel_size : float, optional
21        The physical size of a pixel in the specified units. Default is 1.
22    units : str, optional
23        The units of measurement for the pixel size (e.g., "pixel", "nm", "um"). Default is "pixel".
24    plot_frc_curve : bool, optional
25        If True, plots the FRC curve. Default is False.
26
27    Returns
28    -------
29    float
30        The resolution estimate based on the FRC calculation.
31
32    Notes
33    -----
34    The Fourier Ring Correlation (FRC) is a method to estimate the resolution of images, particularly useful in microscopy. It compares the similarity of two images in the frequency domain, providing a measure of their resolution.
35    """
36    frc_calc = FIRECalculator(pixel_size=pixel_size, units=units)
37    res = frc_calc.calculate_fire_number(frame_1, frame_2)
38
39    if plot_frc_curve:
40        plt.axis("off")
41        plt.subplots_adjust(left=0, right=1, top=1, bottom=0, wspace=0, hspace=0)
42        plt.imshow(frc_calc.plot_frc_curve())
43        plt.show()
44
45    return res

Calculate the Fourier Ring Correlation (FRC) between two images to estimate their resolution.

Parameters

frame_1 : np.ndarray The first image frame as a 2D numpy array. frame_2 : np.ndarray The second image frame as a 2D numpy array. pixel_size : float, optional The physical size of a pixel in the specified units. Default is 1. units : str, optional The units of measurement for the pixel size (e.g., "pixel", "nm", "um"). Default is "pixel". plot_frc_curve : bool, optional If True, plots the FRC curve. Default is False.

Returns

float The resolution estimate based on the FRC calculation.

Notes

The Fourier Ring Correlation (FRC) is a method to estimate the resolution of images, particularly useful in microscopy. It compares the similarity of two images in the frequency domain, providing a measure of their resolution.

def calculate_decorr_analysis( frame: numpy.ndarray, rmin: float = 0, rmax: float = 1, n_r: int = 50, n_g: int = 10, pixel_size: float = 1, units: str = 'pixel', roi: tuple = (0, 0, 0, 0), plot_decorr_analysis=False):
 48def calculate_decorr_analysis(
 49    frame: np.ndarray,
 50    rmin: float = 0,
 51    rmax: float = 1,
 52    n_r: int = 50,
 53    n_g: int = 10,
 54    pixel_size: float = 1,
 55    units: str = "pixel",
 56    roi: tuple = (0, 0, 0, 0),
 57    plot_decorr_analysis=False,
 58):
 59    """
 60    Perform decorrelation analysis on a given image frame to estimate its resolution.
 61
 62    Parameters
 63    ----------
 64    frame : np.ndarray
 65        The image frame as a 2D numpy array.
 66    rmin : float, optional
 67        The minimum radius for decorrelation analysis. Default is 0.
 68    rmax : float, optional
 69        The maximum radius for decorrelation analysis. Default is 1.
 70    n_r : int, optional
 71        The number of radial divisions for analysis. Default is 50.
 72    n_g : int, optional
 73        The number of angular divisions for analysis. Default is 10.
 74    pixel_size : float, optional
 75        The physical size of a pixel in the specified units. Default is 1.
 76    units : str, optional
 77        The units of measurement for the pixel size (e.g., "pixel", "nm", "um"). Default is "pixel".
 78    roi : tuple, optional
 79        The region of interest in the format (x_min, y_min, x_max, y_max). Default is (0, 0, 0, 0).
 80    plot_decorr_analysis : bool, optional
 81        If True, plots the results of the decorrelation analysis. Default is False.
 82
 83    Returns
 84    -------
 85    float
 86        The resolution estimate based on the decorrelation analysis.
 87
 88    Notes
 89    -----
 90    Decorrelation analysis is a technique used to estimate the resolution of images by analyzing the decorrelation of intensity values over different spatial scales. It is particularly useful in microscopy and imaging where direct resolution measurement is challenging.
 91    """
 92    decorr_calc = DecorrAnalysis(pixel_size=pixel_size, units=units, rmin=rmin, rmax=rmax, n_r=n_r, n_g=n_g, roi=roi)
 93    decorr_calc.run_analysis(frame)
 94
 95    if plot_decorr_analysis:
 96        plt.axis("off")
 97        plt.subplots_adjust(left=0, right=1, top=1, bottom=0, wspace=0, hspace=0)
 98        plt.imshow(decorr_calc.plot_results())
 99        plt.show()
100
101    return decorr_calc.resolution

Perform decorrelation analysis on a given image frame to estimate its resolution.

Parameters

frame : np.ndarray The image frame as a 2D numpy array. rmin : float, optional The minimum radius for decorrelation analysis. Default is 0. rmax : float, optional The maximum radius for decorrelation analysis. Default is 1. n_r : int, optional The number of radial divisions for analysis. Default is 50. n_g : int, optional The number of angular divisions for analysis. Default is 10. pixel_size : float, optional The physical size of a pixel in the specified units. Default is 1. units : str, optional The units of measurement for the pixel size (e.g., "pixel", "nm", "um"). Default is "pixel". roi : tuple, optional The region of interest in the format (x_min, y_min, x_max, y_max). Default is (0, 0, 0, 0). plot_decorr_analysis : bool, optional If True, plots the results of the decorrelation analysis. Default is False.

Returns

float The resolution estimate based on the decorrelation analysis.

Notes

Decorrelation analysis is a technique used to estimate the resolution of images by analyzing the decorrelation of intensity values over different spatial scales. It is particularly useful in microscopy and imaging where direct resolution measurement is challenging.