FRC_lib

FRC(im1, im2)[source]

Fourier Ring Correlation. It requires two identical images, differing only in the noise content.

Parameters:
  • im1 (np.array(N x M)) – First input image

  • im2 (np.array(N x M)) – Second input image

Returns:

FRC – Raw FRC curve

Return type:

np.array()

FRC_resolution(I1, I2, px=1, method='fixed', smoothing='lowess')[source]

Fourier Ring Correlation analysis. It requires two identical images, differing only in the noise content, and estimates the resolution from the FRC curve.

Parameters:
  • I1 (np.array(N x M)) – First input image

  • I2 (np.array(N x M)) – Second input image

  • px (float) – Pixel size of the images

  • method (str) – Threshold criterium. If ‘fixed’, it uses the 1/7 threshold. Other possibilities are ‘3sigma’ and ‘5sigma’

  • smoothing (str) – Smoothing method for the FRC curve. If ‘lowess’ it smooths and interpolates the curve using a lowess algorithm. If ‘fit’ it fits the curve with a sigmoid model and removes high-frequency offset, if present. Default is ‘lowess’.

Returns:

  • res_um (float) – Estimated resolution, in real units

  • k (np.array( np.sqrt(N**2 + M**2) )) – Array of spatial frequencies

  • frc (np.array( np.sqrt(N**2 + M**2) )) – Array of raw FRC

  • k_interp (np.array( 100 x np.sqrt(N**2 + M**2) )) – Interpolated array of spatial frequencies

  • frc_smooth (np.array( 100 x np.sqrt(N**2 + M**2) )) – Interpolated and smoothed FRC curve

  • th (np.array( 100 x np.sqrt(N**2 + M**2) )) – Threshold curve

fixed_threshold(frc, y)[source]

Calculate the treshold for the FRC analysis

Parameters:
  • frc (np.ndarray) – FRC values

  • y (float) – Threshold value

Returns:

  • th (float) – Threshold value

  • idx (int) – Index where threshold value is reached

hann2d(*args)[source]

Bi-dimensional Hann windowing function

Parameters:
  • N (int) – Shape of the image (N x M). If only N is provided, a squared image (N x N) is assumed.

  • M (int) – Shape of the image (N x M)

Returns:

W – Hann window function

Return type:

np.array(N x M)

nsigma_threshold(k, frc, img, sigma)[source]

Find the treshold for the FRC analysis

Parameters:
  • k (np.ndarray) – Frequencies array (N)

  • frc (np.ndarray) – FRC value for each k value (N)

  • img (np.ndarray()) – Image used to calculate the radial profile

  • sigma (int) – Criterium used for the threshold (3 for ‘3 sigma’ criterium, etc.)

Returns:

  • th_interp (float) – Threshold

  • idx2 (int) – Index where threshold value is reached

plotFRC(res_um, k, frc, k_interp, frc_smooth, th, fig=None, ax=None)[source]

Visualization of the results of the FRC curve. The inputs are exactly the outputs of FRC_resolution function.

Parameters:
  • res_um (float) – Estimated resolution, in real units

  • k (np.array( np.sqrt(N**2 + M**2) )) – Array of spatial frequencies

  • frc (np.array( np.sqrt(N**2 + M**2) )) – Array of raw FRC

  • k_interp (np.array( 100 x np.sqrt(N**2 + M**2) )) – Interpolated array of spatial frequencies

  • frc_smooth (np.array( 100 x np.sqrt(N**2 + M**2) )) – Interpolated and smoothed FRC curve

  • th (np.array( 100 x np.sqrt(N**2 + M**2) )) – Threshold curve

Returns:

  • fig (plt.Figure) – Matplotlib figure.

  • ax (plt.axis) – Matplotlib axis.

radial_profile(data, center)[source]

Calculation of the radial profile of an image

Parameters:
  • data (np.array(N x M)) – image

  • center (np.array(2)) – indices of the center of the image

Returns:

  • radialprofile (np.array( np.sqrt(N**2 + M**2) )) – sum of the data over the angular coordinate

  • nr (int) – number of pixels in the angular bin

smooth(x, y)[source]

Apply smoothing filter based on lowess

Parameters:
  • x (np.array(N)) – horizontal axis

  • y (np.array(N)) – noisy array

Returns:

  • x_interpolated (np.array(100 x N)) – interpolated x-axis

  • y_filtered (np.array(100 x N)) – interpolated and smoothed array

timeFRC(dset, px=1, method='fixed', smoothing='lowess')[source]

Fourier Ring Correlation analysis. It requires a single dataset with a temporal dimension to generate two images using the even and odd indices of the time axis. Then, it estimates the resolution using the FRC analysis.

Parameters:
  • dset (np.ndarray) – dataset (Nx x Ny x Nt)

  • px (float) – Pixel size of the images

  • method (str) – Threshold criterium. If ‘fixed’, it uses the 1/7 threshold. Other possibilities are ‘3sigma’ and ‘5sigma’

  • smoothing (str) – Smoothing method for the FRC curve. If ‘lowess’ it smooths and interpolates the curve using a lowess algorithm. If ‘fit’ it fits the curve with a sigmoid model and removes high-frequency offset, if present. Default is ‘lowess’.

Returns:

  • res_um (float) – Estimated resolution, in real units

  • k (np.array( np.sqrt(N**2 + M**2) )) – Array of spatial frequencies

  • frc (np.array( np.sqrt(N**2 + M**2) )) – Array of raw FRC

  • k_interp (np.array( 100 x np.sqrt(N**2 + M**2) )) – Interpolated array of spatial frequencies

  • frc_smooth (np.array( 100 x np.sqrt(N**2 + M**2) )) – Interpolated and smoothed FRC curve

  • th (np.array( 100 x np.sqrt(N**2 + M**2) )) – Threshold curve