Tutorial about Fourier Ring Correlation (FRC) analysis¶
Fourier Ring Correlation provides a resolution measure that takes both localization precision and label density into account.
import logging
import warnings
from pathlib import Path
from copy import copy, deepcopy
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import locan as lc
lc.show_versions(system=False, dependencies=False, verbose=False)
Locan:
version: 0.24.0.dev1+g34ee40bb9
Python:
version: 3.11.15
FRC for dSTORM data¶
First, let us look at FRC for dSTORM data showing nuclear pore complexes.
locdata = lc.load_npc()
print(f"Metadata:\n")
locdata.print_summary()
Jupyter environment detected. Enabling Open3D WebVisualizer.
[Open3D INFO] WebRTC GUI backend enabled.
[Open3D INFO] WebRTCWindowSystem: HTTP handshake server disabled.
Metadata:
identifier: "13"
comment: ""
source: EXPERIMENT
state: RAW
element_count: 2285189
frame_count: 24999
file {
type: ASDF
path: "/home/docs/.cache/locan_datasets/npc_gp210.asdf"
}
creation_time {
2026-11-30T11:40:46.898420Z
}
lc.render_2d(locdata, rescale=lc.Trafo.EQUALIZE, bin_size=10);
frc = lc.FourierRingCorrelation(bin_size=10, smooth=1)
frc.compute(locdata)
frc.plot();
To reduce boundary effects a windowing function must be applied using scipy window functions. Often, a Tukey window with alpha 1/8 is used in SMLM.
frc = lc.FourierRingCorrelation(bin_size=10, window=("tukey", 0.25), smooth=1)
frc.compute(locdata)
frc.plot();
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 7))
axes[0].imshow(frc.results.image.data, vmax=0.1)
axes[1].imshow(frc.results.other_image.data, vmax=0.1);
The results are accessible in a dedicated FrcResults class that also provides a method to compute a threshold frequency or resolution (defined as the inverse threshold frequency).
print(frc.results)
print(f"Threshold frequency:", round(frc.results.threshold_frequency(), 4))
print(f"Resolution:", round(frc.results.resolution()))
FourierRingCorrelationResults()
Threshold frequency: 0.0305
Resolution: 33
The two image representations used for FRC computation are provided as Image object. Note that the images are not intensity equalized as often done for visualization.
frc.results.image.shape, frc.results.other_image.shape
((2892, 2265), (2892, 2265))
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 7))
axes[0].imshow(frc.results.image.data, vmax=0.1)
axes[1].imshow(frc.results.other_image.data, vmax=0.1);
FRC for dSTORM data on smaller regions of interest¶
Analyzing a smaller region of interest further indicates that using a window filter, typically a Tukey filter with alpha=0.8, makes the FRC result more reliable (meaning resolution becomes larger).
locdata_roi = lc.select_by_condition(
locdata, condition="position_x<8_000 and position_y<8_000"
)
locdata_roi.reduce()
print(f"Metadata:\n")
locdata_roi.print_summary()
Metadata:
identifier: "8"
comment: ""
source: EXPERIMENT
state: MODIFIED
element_count: 176737
frame_count: 24931
file {
type: ASDF
path: "/home/docs/.cache/locan_datasets/npc_gp210.asdf"
}
creation_time {
2026-11-30T11:40:46.898420Z
}
modification_time {
2026-11-30T11:40:46.898420Z
}
lc.render_2d(locdata_roi, bin_size=10, rescale=lc.Trafo.EQUALIZE);
lc.render_2d(locdata_roi, bin_size=10, rescale=lc.Trafo.STANDARDIZE, vmax=0.1);
frc = lc.FourierRingCorrelation(bin_size=10, smooth=1)
frc.compute(locdata_roi)
frc.plot();
High frequency contributions result from boundary effects that should be reduced by applying window functions.
Applying a Tukey window¶
frc = lc.FourierRingCorrelation(bin_size=10, window=("tukey", 0.25), smooth=1)
frc.compute(locdata_roi)
frc.plot();
Choosing the alpha parameter in Tukey windowing¶
When using a Tukey window, the precise value of alpha is not that important.
frc_batch = []
windows = [None, ("tukey", 0)] + [
("tukey", alpha_) for alpha_ in np.logspace(-2, 0, 10)
]
for window_ in windows:
frc = lc.FourierRingCorrelation(bin_size=10, window=window_, smooth=1)
frc.compute(locdata_roi)
frc_batch.append(frc)
frc_batch
[FourierRingCorrelation(bin_size=10, smooth=1, window=None),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', 0)),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', np.float64(0.01))),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', np.float64(0.016681005372000592))),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', np.float64(0.027825594022071243))),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', np.float64(0.046415888336127774))),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', np.float64(0.0774263682681127))),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', np.float64(0.1291549665014884))),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', np.float64(0.21544346900318834))),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', np.float64(0.3593813663804626))),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', np.float64(0.5994842503189409))),
FourierRingCorrelation(bin_size=10, smooth=1, window=('tukey', np.float64(1.0)))]
for frc_ in frc_batch:
frc_.plot()
fig, axes = plt.subplots(nrows=1, ncols=5, figsize=(15, 5))
axes[0].imshow(frc_batch[0].results.image.data, cmap="cet_fire", vmax=1)
axes[1].imshow(frc_batch[1].results.image.data, cmap="cet_fire", vmax=1)
axes[2].imshow(frc_batch[2].results.image.data, cmap="cet_fire", vmax=1)
axes[3].imshow(frc_batch[7].results.image.data, cmap="cet_fire", vmax=1)
axes[4].imshow(frc_batch[-1].results.image.data, cmap="cet_fire", vmax=1);
Detailed FRC workflow¶
For further choices with regard to image preparation make use of upstream analysis functions. The following examples show the influence of histogram equalization and windowing on the FRC.
collection = lc.LocData.from_chunks(
locdata=locdata_roi, n_chunks=2, order="alternating"
)
bin_range = lc.range_from_collection(locdatas=collection.references)
bins = lc.Bins.from_bin_size(10, bin_range)
images = [
lc.histogram(locdata=locdata_, bins=bins).data for locdata_ in collection.references
]
images_standardized = [
lc.adjust_contrast(image_, rescale=lc.Trafo.STANDARDIZE) for image_ in images
]
images_equalized = [
lc.adjust_contrast(image_, rescale=lc.Trafo.EQUALIZE) for image_ in images
]
images_windowed = [
lc.apply_window(image_, window_function="tukey", alpha=0.25) for image_ in images
]
images_equalized_windowed = [
lc.apply_window(image_, window_function="tukey", alpha=0.25)
for image_ in images_equalized
]
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(15, 5))
axes[0].imshow(images[0], cmap="cet_fire")
axes[1].imshow(images_equalized[0], cmap="cet_fire")
axes[2].imshow(images_equalized_windowed[0], cmap="cet_fire");
for label_, imgs_ in zip(
["original", "standardized", "equalized", "windowed", "equalized_windowed"],
[
images,
images_standardized,
images_equalized,
images_windowed,
images_equalized_windowed,
],
):
img = imgs_[0]
print(
label_ + ": ",
f"Min intensity: {img.min():0.2f}",
f"Max intensity: {img.max():0.2f}",
"Data type:",
img.dtype,
)
original: Min intensity: 0.00 Max intensity: 114.00 Data type: float64
standardized: Min intensity: 0.00 Max intensity: 1.00 Data type: float64
equalized: Min intensity: 0.00 Max intensity: 1.00 Data type: float64
windowed: Min intensity: 0.00 Max intensity: 23.00 Data type: float64
equalized_windowed: Min intensity: 0.00 Max intensity: 1.00 Data type: float64
Compute the FRC for all image representations.
images_preprocessed = lc.analysis.fourier_ring_correlation.preprocess_images(*images)
frc_result = lc.analysis.fourier_ring_correlation.compute_fourier_ring_correlation(
*images_preprocessed, bin_size=10
)
images_preprocessed = lc.analysis.fourier_ring_correlation.preprocess_images(
*images_standardized
)
frc_result_standardized = (
lc.analysis.fourier_ring_correlation.compute_fourier_ring_correlation(
*images_preprocessed, bin_size=10
)
)
images_preprocessed = lc.analysis.fourier_ring_correlation.preprocess_images(
*images_equalized
)
frc_result_equalized = (
lc.analysis.fourier_ring_correlation.compute_fourier_ring_correlation(
*images_preprocessed, bin_size=10
)
)
images_preprocessed = lc.analysis.fourier_ring_correlation.preprocess_images(
*images_windowed
)
frc_result_windowed = (
lc.analysis.fourier_ring_correlation.compute_fourier_ring_correlation(
*images_preprocessed, bin_size=10
)
)
images_preprocessed = lc.analysis.fourier_ring_correlation.preprocess_images(
*images_equalized_windowed
)
frc_result_equalized_windowed = (
lc.analysis.fourier_ring_correlation.compute_fourier_ring_correlation(
*images_preprocessed, bin_size=10
)
)
Plot the results
plt.plot(frc_result.frequency, frc_result.correlation, label="original")
plt.plot(
frc_result_standardized.frequency,
frc_result_standardized.correlation,
label="standardized",
)
plt.plot(
frc_result_equalized.frequency, frc_result_equalized.correlation, label="equalized"
)
plt.plot(
frc_result_windowed.frequency, frc_result_windowed.correlation, label="windowed"
)
plt.plot(
frc_result_equalized_windowed.frequency,
frc_result_equalized_windowed.correlation,
label="equalized and windowed",
)
plt.legend();
Linking localizations¶
The fact, that in dSTORM multiple localizations arise from the same emitter, results in an apparent resolution improvement due those repeated detection events varying in space by just the localization precision.
Linking localizations that appear in successive frames and that are close in space, reduces this spurious resolution contribution.
locdata_smaller_roi = lc.select_by_condition(
locdata, condition="6_000 < position_x < 7_000 and 4_000 < position_y < 5_000"
)
locdata_smaller_roi.reduce()
print(f"Metadata:\n")
locdata_smaller_roi.print_summary()
Metadata:
identifier: "54"
comment: ""
source: EXPERIMENT
state: MODIFIED
element_count: 2119
frame_count: 2103
file {
type: ASDF
path: "/home/docs/.cache/locan_datasets/npc_gp210.asdf"
}
creation_time {
2026-11-30T11:40:46.898420Z
}
modification_time {
2026-11-30T11:40:46.898420Z
}
lc.render_2d(locdata_smaller_roi, bin_size=10, rescale=lc.Trafo.EQUALIZE);
frc = lc.FourierRingCorrelation(bin_size=10, window=("tukey", 0.25), smooth=1)
frc.compute(locdata_smaller_roi)
frc.plot();
trackpy_logger = logging.getLogger("trackpy")
trackpy_logger.setLevel(logging.WARN)
%%time
locdata_linked, _ = lc.track(locdata_smaller_roi, search_range=50, memory=10)
locdata_linked.region = locdata.region
locdata_linked.reduce(reset_index=True)
locdata_linked.print_summary()
identifier: "1174"
comment: ""
source: DESIGN
state: RAW
element_count: 1116
frame_count: 1112
creation_time {
2026-11-30T11:41:06.076209Z
}
CPU times: user 321 ms, sys: 3.93 ms, total: 325 ms
Wall time: 324 ms
lc.render_2d(locdata_linked, bin_size=10, rescale=lc.Trafo.EQUALIZE);
frc = lc.FourierRingCorrelation(bin_size=10, window=("tukey", 0.25), smooth=1)
frc.compute(locdata_linked)
frc.plot();