SMLMFrameConnection
Frame-connection for 2D single molecule localization microscopy (SMLM) data: linking localizations from the same fluorophore blinking event across consecutive frames into single, higher-precision localizations. Uses spatiotemporal LAP assignment to optimally connect temporally adjacent detections based on spatial proximity and estimated blinking kinetics. See Schodt & Lidke 2021.
Installation
using Pkg
Pkg.add("SMLMFrameConnection")Quick Start
using SMLMFrameConnection
# Run frame connection on your BasicSMLD with Emitter2DFit emitters
(combined, info) = frameconnect(smld)
# combined is the main output - higher precision localizations
# info contains track assignments and algorithm metadataInput Requirements
Input BasicSMLD must contain Emitter2DFit emitters with:
Required:
x,y: Position coordinates (microns), finiteσ_x,σ_y: Position uncertainties (microns), finite and > 0σ_xy: Position covariance (μm²); the covariance must be positive definite,|σ_xy| < σ_x σ_yframe: Frame number; forframeconnect, at least 1, andsmld.n_framesis at least the largest frame, or 0 (unknown)
Optional:
photons,bg: Photometry (summed in output)dataset: Dataset identifier (default: 1)
frameconnect refuses input that breaks these with an ArgumentError naming the localization and field; combinelocalizations checks the same except the frame rules (it only groups by track and takes each track's earliest frame). Localizations that carry z (3D) are refused the same way by both; frame connection is 2D only.
Localizations may come in any order (for example SMLMSim's output, grouped by emitter): frameconnect works on a copy sorted by every field, so the result is the same for any input order, and info.connected keeps the caller's order.
combinelocalizations combines localizations that share a track_id within a dataset. track_id 0 means unlinked: each such localization passes through on its own, as does a track of one localization.
Algorithm Overview
- Preclustering: Groups spatially and temporally adjacent localizations into candidate clusters
- Parameter Estimation: Estimates fluorophore blinking kinetics (
k_on,k_off,k_bleach) and emitter density from the data - Frame Connection: Uses Linear Assignment Problem (LAP) to optimally assign localizations to emitters based on spatial proximity and estimated photophysics
- Combination: Combines connected localizations using MLE weighted mean for improved precision
Outputs
| Output | Description |
|---|---|
combined | Main output - combined high-precision localizations |
info.connected | Original localizations with track_id assigned |
info.n_tracks | Number of tracks formed |
info.elapsed_s | Wall time in seconds |
Parameters
frameconnect(smld;
n_density_neighbors = 2, # Clusters for density estimation
max_sigma_dist = 5.0, # Distance threshold multiplier
max_frame_gap = 5, # Max frame gap for connections
max_neighbors = 2, # Nearest neighbors for preclustering
track_length = nothing # Inclusive (min,max) locs-per-track filter; nothing disables
)max_sigma_dist: Higher values allow connections over larger distancesmax_frame_gap: Increase for dyes with long dark states (dSTORM: 10-20)track_length:(2.0, Inf)drops single-frame blinks;(2.0, 50.0)also drops over-long tracks (fiducials, sticky strands). Count dropped is reported ininfo.n_filtered
API Reference
SMLMFrameConnection.CalibrationConfigSMLMFrameConnection.CalibrationResultSMLMFrameConnection.FrameConnectConfigSMLMFrameConnection.FrameConnectInfoSMLMFrameConnection.ParamStructSMLMFrameConnection._check_2dSMLMFrameConnection._check_inputsSMLMFrameConnection.analyze_calibrationSMLMFrameConnection.apply_calibrationSMLMFrameConnection.combinelocalizationsSMLMFrameConnection.compress_connectIDSMLMFrameConnection.compress_connectID!SMLMFrameConnection.computeclusterinfoSMLMFrameConnection.connect1DSSMLMFrameConnection.connectlocalizationsSMLMFrameConnection.connectlocalizations!SMLMFrameConnection.create_costmatrixSMLMFrameConnection.defineidealFCSMLMFrameConnection.estimatedensitiesSMLMFrameConnection.estimateparamsSMLMFrameConnection.frameconnectSMLMFrameConnection.linkclustersSMLMFrameConnection.linkclusters!SMLMFrameConnection.organizeclustersSMLMFrameConnection.preclusterSMLMFrameConnection.solveLAP
SMLMFrameConnection.CalibrationConfig — TypeCalibrationConfigConfiguration for optional uncertainty calibration within frame connection.
Calibration analyzes frame-to-frame jitter within connected tracks to estimate a motion variance (σ_motion²) and CRLB scale factor (k²), then applies corrected uncertainties before track combination: Σ_corrected = σ_motion² I + k² Σ_CRLB.
Fields
clamp_k_to_one::Bool=true: Hold k_scale ≥ 1.0 (CRLB is a lower bound); when the fit gives k < 1, the motion term is refit with k = 1filter_high_chi2::Bool=false: Deprecated and ignored (truelogs a warning). It dropped tracks with a pair chi² abovechi2_filter_thresholdunder the uncalibrated CRLB, which are the tracks that show k > 1, so it biasedk_scaletoward 1 (on SMLMSim data with true k 1.5 it gave 1.05). The fit itself leaves out mismatched pairs (seeCalibrationResult).chi2_filter_threshold::Float64=6.0: Deprecated and ignored, withfilter_high_chi2
SMLMFrameConnection.CalibrationResult — TypeCalibrationResultOutput diagnostics from uncertainty calibration. Returned in FrameConnectInfo.calibration when calibration is enabled.
The calibration model fits: observed_var = A + B * CRLB_var where observed_var is the per-axis variance of the difference of two consecutive localizations, CRLB_var the sum of their per-axis CRLB variances, so the intercept is A = 2σ_motion² (each localization carries its own motion/vibration jitter) and B = k² (CRLB scale factor).
The fit leaves out pairs whose chi² under the current fit (with the pair's full covariance, σxy included) exceeds the chi²(2) 99.7% point (mismatched pairs), corrects the truncated bin means for the variance the cut removes, and iterates to convergence. Away from its bounds, `kscaleandsigmamotionnmare unbiased within noise under the model (simulated data, 1,000 pairs or more). Near a bound the estimate is pushed away from it, as for any fit held to one. With no motion, σ_motion ≥ 0 biaseskscaledown andsigmamotionnmup: by about 1.5–2% and 1 nm at 1,000 pairs, 0.5% and 0.5 nm at 10,000 (clampktoone = false). Withclampktooneand a true k of 1, k ≥ 1 biaseskscale` up: by about 2–3% at 1,000 pairs with a 5–10 nm motion term, 0.6% at 10,000.
Fields
sigma_motion_nm::Float64: Applied per-localization motion std dev in nm (√(A_applied/2) × 1000)k_scale::Float64: Applied CRLB scale factor (√B_applied)A::Float64: Intercept of the free two-parameter fit (pair-difference variance 2σ_motion², in μm²); can be negativeB::Float64: Slope of the free two-parameter fit (k²). The lineA + B * bin_centersgoes throughbin_observed.B < 1whileB_applied == 1means the clamp boundA_sigma::Float64: Standard error of AB_sigma::Float64: Standard error of Br_squared::Float64: Weighted R² of the WLS fit (about the weighted mean)mean_chi2::Float64: Mean chi² (full pair covariance, uncalibrated CRLB) across all frame-to-frame pairsn_pairs::Int: Number of frame-to-frame pairs used in the final fit: kept by its chi² cut, inside the bins' span and in bins of 5 or more. On a fallback, the same count for the last fit attempted, or all pairs when there were fewer than 100n_tracks_used::Int: Number of tracks contributing pairsn_tracks_filtered::Int: Always 0 (the deprecated track filter is ignored)bin_centers::Vector{Float64}: Bin centers (CRLB variance) for diagnostic plotsbin_observed::Vector{Float64}: Bin observed variance (truncation-corrected) of the free fit, for diagnostic plotsbin_counts::Vector{Int}: Number of pairs per bin (parallel to bincenters/binobserved); use to grey/drop low-statistics bins in diagnostic plotsframe_shifts::Dict{Int, Vector{NTuple{2,Float64}}}: Per-dataset (dx,dy) shifts for jitter plotscalibration_applied::Bool: Whether calibration was actually applied (false on fallback)warning::String: Why calibration fell back (too few pairs or bins, or motion and CRLB scale not separable), or, on an applied calibration, that the fit did not converge (empty if OK)A_applied::Float64: Intercept applied, in μm² (≥ 0): the free fit's, or a refit with a bound held (A ≥ 0; B ≥ 1 withclamp_k_to_one). 0 on fallbackB_applied::Float64: Slope applied (k², > 0, ≥ 1 with the clamp). 1 on fallback
SMLMFrameConnection.FrameConnectConfig — TypeFrameConnectConfigConfiguration parameters for frame connection algorithm.
Fields
n_density_neighbors::Int=2: Number of nearest preclusters used for local density estimates (seeestimatedensities)max_sigma_dist::Float64=5.0: Multiplier of localization errors that defines a pre-clustering distance threshold (seeprecluster)max_frame_gap::Int=5: Maximum frame gap between temporally adjacent localizations in a precluster (seeprecluster)max_neighbors::Int=2: Maximum number of nearest-neighbors inspected for precluster membership (seeprecluster)track_length::Union{Tuple{Float64,Float64}, Nothing}=nothing: Inclusive(min, max)range on the number of localizations a track must contain to be emitted as a combined localization (lo <= nperID <= hi). Counts localizations sharing atrack_id, not temporal frame-span.nothing(default) disables filtering. Use(2.0, Inf)to drop single-frame blinks, or(2.0, 50.0)to also drop over-long tracks (e.g. fiducials, sticky docking strands in dense DNA-PAINT). Mirrors the(min, max)filter idiom used elsewhere in the ecosystem. Seecombinelocalizations.calibration::Union{CalibrationConfig, Nothing}=nothing: Optional uncertainty calibration
Example
# Without calibration (default)
(combined, info) = frameconnect(smld)
# With calibration
config = FrameConnectConfig(calibration=CalibrationConfig())
(combined, info) = frameconnect(smld, config)SMLMFrameConnection.FrameConnectInfo — TypeFrameConnectInfo{T}Secondary output from frameconnect() containing track assignments and algorithm metadata.
Fields
connected::BasicSMLD{T}: Input SMLD with track_id assigned (localizations uncombined)n_input::Int: Number of input localizationsn_tracks::Int: Number of tracks formed (connection-stage count, pre length-filter)n_combined::Int: Number of output localizations (post length-filter)n_filtered::Int: Number of tracks dropped for falling outside thetrack_lengthrange. Whentrack_length === nothing(default) this is0. Noten_tracks - n_combined == n_filteredwhile the length filter is the only cause of dropped tracks.k_on::Float64: Estimated on rate (1/frame)k_off::Float64: Estimated off rate (1/frame)k_bleach::Float64: Estimated bleach rate (1/frame)p_miss::Float64: Probability of missed detectioninitial_density::Vector{Float64}: Initial density estimate per cluster (emitters/μm²)elapsed_s::Float64: Wall time in secondsalgorithm::Symbol: Algorithm used (:lap)n_preclusters::Int: Number of preclusters formedcalibration::Union{CalibrationResult, Nothing}: Calibration diagnostics (nothing if disabled)
Rate Parameter Interpretation
The rate parameters describe the photophysics of blinking fluorophores:
k_on: Rate at which dark emitters convert to visible statek_off: Rate at which visible emitters convert to reversible dark statek_bleach: Rate at which visible emitters are irreversibly photobleached- Duty cycle = kon / (kon + k_off)
- For typical dSTORM: kon << koff (low duty cycle, mostly dark with brief blinks)
Example
(combined, info) = frameconnect(smld)
println("Connected $(info.n_input) → $(info.n_combined) localizations")
println("Formed $(info.n_tracks) tracks in $(info.elapsed_s)s")
# Access track assignments via info.connected
# Check calibration results if enabled
if info.calibration !== nothing
println("k_scale = $(info.calibration.k_scale)")
println("σ_motion = $(info.calibration.sigma_motion_nm) nm")
endSMLMFrameConnection.ParamStruct — TypeParamStruct(initial_density::Vector{Float64},
k_on::Float64, k_off::Float64, k_bleach::Float64, p_miss::Float64,
max_sigma_dist::Float64, max_frame_gap::Int, n_density_neighbors::Int)Structure of parameters needed for frame-connection.
Fields
initial_density: Density of emitters at the start of the experiment. (see estimatedensities()) (emitters/μm²)n_density_neighbors: Number of nearest preclusters used for local density estimates. (default = 2)(see estimatedensities())k_on: Rate at which dark emitters convert to the visible state (1/frame).k_off: Rate at which visible emitters convert to the reversible dark state (1/frame).k_bleach: Rate at which visible emitters are irreversibly photobleached (1/frame).p_miss: Probability of missing a localization of a visible emitter.max_sigma_dist: Multiplier of localization errors that defines a pre-clustering distance threshold. (default = 5)(see precluster())(unitless)max_frame_gap: Maximum frame gap between temporally adjacent localizations in a precluster. (default = 5)(see precluster())(frames)max_neighbors: Maximum number of nearest-neighbors inspected for precluster membership. Ideally, this would be set to inf, but that's not feasible for most data. (default = 2)(see precluster())
Note: kon, koff, and kbleach are transition rates, not duty cycle fractions. The duty cycle (fraction of time in ON state) is kon/(kon + koff). For typical dSTORM, kon << koff gives low duty cycle (mostly dark, brief blinks).
SMLMFrameConnection._check_2d — Method_check_2d(smld, fname)Throw an ArgumentError if any localization in smld carries a z coordinate. Frame connection is 2D: it builds Emitter2DFit output and would silently drop z and σ_z.
SMLMFrameConnection._check_inputs — Method_check_inputs(smld, fname; frames = true)Throw an ArgumentError naming the localization and field when an input would hang the LAP or give wrong numbers without an error: a non-finite position; σx or σy not finite and > 0 (a zero σ gives NaN combined positions, a NaN σ NaN costs); a covariance σxy that is not finite or leaves Σ not positive definite; and, with frames, a frame below 1 (frames are 1-based) or an `nframessmaller than the largest frame (n_frames = 0` means unknown and is allowed).
SMLMFrameConnection.analyze_calibration — Methodanalyze_calibration(smld::BasicSMLD, config::CalibrationConfig) -> CalibrationResultAnalyze frame-to-frame jitter in connected tracks to estimate uncertainty calibration parameters.
Collects consecutive-frame pairs within each track, computes observed positional variance vs CRLB variance, and fits the model: observed_var = A + B * CRLB_var using weighted least squares on binned data. A = 2σ_motion² (both localizations of a pair carry motion jitter) and B = k². Pairs whose chi² under the current fit (with the pair's full covariance, σ_xy included) exceeds the chi²(2) 99.7% point are left out as mismatches; the truncated bin means are corrected for the variance the cut removes, and the fit iterates to convergence.
The fit is applied only when it separates the two terms: slope positive and at least 3 standard errors, and R² ≥ 0.1. A determined fit whose bound binds (A < 0, or B < 1 with clamp_k_to_one) is refit with that parameter held at its bound.
Falls back gracefully (returns calibration_applied=false, with the reason in warning) if fewer than 100 frame-to-frame pairs are available, the reported precisions fill fewer than 3 bins (reported precisions whose range is at most 1e-12 of the largest are one value, one bin), the fit cannot separate the two terms (a narrow range of reported precisions, or a dominant motion term), a bound refit keeps fewer than 3 bins after its own cut, or fewer than 100 pairs remain in the applied fit after the cut.
SMLMFrameConnection.apply_calibration — Methodapply_calibration(smld::BasicSMLD, result::CalibrationResult) -> BasicSMLDApply calibrated uncertainties to emitters. Returns a new SMLD with corrected covariance: Σ_corrected = σ_motion² I + k² Σ_CRLB.
Only modifies σx, σy, σ_xy. Positions and other fields are unchanged.
SMLMFrameConnection.combinelocalizations — Methodsmld_combined = combinelocalizations(smld::BasicSMLD{T,E};
track_length::Union{Tuple{Float64,Float64},Nothing}=nothing) where {T, E<:SMLMData.AbstractEmitter}Combine clustered localizations in smld into higher precision localizations.
Description
This function combines localizations in smld that share the same value of trackid within one dataset. Localizations are combined assuming they arose from independent measurements of the same position with Gaussian errors. A localization with `trackid == 0` (SMLMData's "unlinked") is passed through on its own. Each combined localization takes frame, dataset and id from its track's earliest localization; the result does not depend on the order of the input.
track_length is an inclusive (min, max) range on the number of localizations per track: a track is emitted only if min <= nperID <= max. nothing (the default) disables filtering. This counts localizations sharing a track_id, not temporal frame-span. Use (2.0, Inf) to drop single-frame blinks, or a finite upper bound like (2.0, 50.0) to also drop over-long tracks (e.g. fiducials or sticky docking strands in dense DNA-PAINT data).
SMLMFrameConnection.compress_connectID! — Methodcompress_connectID!(connectID::Vector{Int32})Make connectID consists of the set of integers 1:length(unique(connectID))`
SMLMFrameConnection.compress_connectID — MethodconnectID = compress_connectID(connectID::Vector{Int32})Make connectID consists of the set of integers 1:length(unique(connectID))`
SMLMFrameConnection.computeclusterinfo — Methodclusterdurations, nobservations =
computeclusterinfo(clusterdata::Vector{Matrix{Float64}})Compute the durations of and number of member localizations in clusters.
Description
This method computes the duration of each cluster and the number of localizations in each cluster present in the input clusterdata.
SMLMFrameConnection.connect1DS — Methodconnect1DS(smld::BasicSMLD{T,E}, dataset::Int,
connectID::Vector{Int}, maxID::Int;
max_frame_gap::Int = 5) where {T, E<:SMLMData.AbstractEmitter}Define the "ideal" frame-connection result for simulated smld with one dataset.
Description
This is a helper function which defines the ideal FC result for a single dataset. The user should probably not bother using this, and instead should call defineidealFC().
Inputs
smld: BasicSMLD with track_id populated to indicate emitter ID.dataset: Dataset number to be connected.connectID: Current connection IDs for all emitters.maxID: Current maximum ID value.max_frame_gap: Maximum frame gap allowed between localizations connected in the "ideal" result.
Returns
- Updated connectID array and new maxID.
SMLMFrameConnection.connectlocalizations! — Methodconnectlocalizations!(connectID::Vector{Int64},
clusterdata::Vector{Matrix{Float64}},
params::ParamStruct, nframes::Int64)Connect localizations in clusterdata by solving a linear assignment problem.
Description
Connect localizations in clusterdata by giving "connected" localizations the same integer value for their field smd.connectID. Associations are made by solving a linear assignment problem which designates the ideal connections between localizations.
SMLMFrameConnection.connectlocalizations — MethodconnectID = connectlocalizations(connectID::Vector{Int64},
clusterdata::Vector{Matrix{Float64}},
params::ParamStruct, nframes::Int64)Connect localizations in clusterdata by solving a linear assignment problem.
Description
Connect localizations in clusterdata by giving "connected" localizations the same integer value for their field smd.connectID. Associations are made by solving a linear assignment problem which designates the ideal connections between localizations.
SMLMFrameConnection.create_costmatrix — Methodcostmatrix = create_costmatrix(clusterdata::Vector{Matrix{Float64}},
params::ParamStruct, clusterind::Int64, nframes::Int64,
base_rho_on::Vector{Float64})Create a cost matrix for connections between localizations in clusterdata.
Description
The costs associated with connecting/not connecting the localizations in the input set of data in clusterdata are placed in entries of the output matrix costmatrix. For N localizations in clusterdata, the output costmatrix will be an 2Nx2N block matrix. The NxN blocks are attributed the following meanings: the upper-left "connection" block corresponds to adding localizations to existing clusters of other localizations, the bottom-left "birth" block corresponds to introduction of a new cluster, and the upper-right "death" block corresponds to preventing admission of any more localizations to a cluster. The bottom-right "auxillary" block is the transpose of the "connection" block. Forbidden connections are indicated by missing.
base_rho_on is a precomputed unit-density on-state density curve of length nframes, shared across all clusters to avoid per-cluster allocation.
SMLMFrameConnection.defineidealFC — Methodsmld_connected, smld_combined = defineidealFC(
smld::BasicSMLD{T,E};
max_frame_gap::Int = 5) where {T, E<:SMLMData.AbstractEmitter}Define the "ideal" frame-connection result for a simulated smld.
Description
This function defines the "ideal" frame connection result from a simulation. That is to say, for a simulated BasicSMLD structure smld with track_id field populated to indicate emitter membership of localizations, this function will generate an "ideal" FC result which combines all blinking events that appeared with frame gaps less than max_frame_gap of one another. Note that for very high duty cycles, multiple blinking events might be mistakingly combined by this method (i.e., if the emitter blinks back on within max_frame_gap frames of its previous blink). Note that localizations are not allowed to be connected across datasets.
Inputs
smld: BasicSMLD with track_id populated to indicate emitter ID.max_frame_gap: Maximum frame gap allowed between localizations connected in the "ideal" result.
Outputs
smld_connected: Copy of the inputsmldwith track_id modified to reflect blinking event ID.smld_combined: Ideal frame-connection result with localizations combined.
SMLMFrameConnection.estimatedensities — Methodinitial_density = estimatedensities(smld::BasicSMLD{T,E},
clusterdata::Vector{Matrix{Float64}}, params::ParamStruct) where {T, E<:SMLMData.AbstractEmitter}Estimate local emitter densities for clusters in smld and clusterdata.
Description
The initial local densities initial_density around each pre-cluster present in smld/clusterdata are estimated based on the local density of pre-clusters throughout the entire set of data as well as some of the rate parameters provided in params.
SMLMFrameConnection.estimateparams — Methodk_on, k_off, k_bleach, p_miss, nemitters =
estimateparams(smld::BasicSMLD{T,E},
clusterdata::Vector{Matrix{Float64}}) where {T, E<:SMLMData.AbstractEmitter}Estimate rate parameters from the clusters in smld and clusterdata.
Description
The rate parameters k_on, k_off, and k_bleach, the probability of missing a localization for a visible emitter p_miss, and the underlying number of emitters nemitters are estimated from the pre-clusters in smld/clusterdata. This is done by assuming that pre-clusters are, on average, representative of a single blinking event of a single emitter.
Citation
Schodt David J., Lidke Keith A., "Spatiotemporal Clustering of Repeated Super-Resolution Localizations via Linear Assignment Problem", Front. Bioinform., 20 October 2021 https://doi.org/10.3389/fbinf.2021.724325
SMLMFrameConnection.frameconnect — Method(combined, info) = frameconnect(smld::BasicSMLD, config::FrameConnectConfig)
(combined, info) = frameconnect(smld::BasicSMLD; kwargs...)Connect repeated localizations of the same emitter in smld.
Description
Repeated localizations of the same emitter present in smld are connected and combined into higher precision localizations of that emitter. This is done by
- forming pre-clusters of localizations, 2) estimating rate parameters from
the pre-clusters, 3) solving a linear assignment problem for connecting localizations in each pre-cluster, and 4) combining the connected localizations using their MLE position estimate assuming Gaussian noise.
Arguments
smld::BasicSMLD: 2D localizations to connect, in any order. Positions must be finite, σx and σy finite and > 0 with a positive-definite covariance, frames 1-based and at mostn_frames(when it is set); otherwise anArgumentErrornames the localization. Localizations that carry z (3D) are refused with anArgumentError; output emitters areEmitter2DFit, so fields beyond those (e.g. a fit p-value) are not carried intoinfo.connected.config::FrameConnectConfig: Configuration parameters (optional, can use kwargs instead)
Keyword Arguments (equivalent to FrameConnectConfig fields)
n_density_neighbors::Int=2: Number of nearest preclusters used for local density estimates (seeestimatedensities)max_sigma_dist::Float64=5.0: Multiplier of localization errors that defines a pre-clustering distance threshold (seeprecluster)max_frame_gap::Int=5: Maximum frame gap between temporally adjacent localizations in a precluster (seeprecluster)max_neighbors::Int=2: Maximum number of nearest-neighbors inspected for precluster membership (seeprecluster)track_length::Union{Tuple{Float64,Float64},Nothing}=nothing: Inclusive(min, max)range on localizations per track; tracks outside it are dropped.nothingis a no-op.(2.0, Inf)removes single-frame blinks;(2.0, 50.0)also drops over-long tracks (fiducials, sticky strands). The number dropped is reported asinfo.n_filtered(seecombinelocalizations).
Returns
A tuple (combined, info):
combined::BasicSMLD: Connected localizations combined into higher precision resultsinfo::FrameConnectInfo: Track assignments and algorithm metadata (seeFrameConnectInfo)
Example
# Using kwargs (most common)
(combined, info) = frameconnect(smld)
(combined, info) = frameconnect(smld; max_frame_gap=10)
# Using config struct
config = FrameConnectConfig(max_frame_gap=10, max_sigma_dist=3.0)
(combined, info) = frameconnect(smld, config)
println("Connected $(info.n_input) → $(info.n_combined) localizations")
println("Formed $(info.n_tracks) tracks from $(info.n_preclusters) preclusters")
# Access track assignments for downstream analysis
track_ids = [e.track_id for e in info.connected.emitters]SMLMFrameConnection.linkclusters! — MethodconnectID, maxconnectID = linkclusters!(connectID::Int64,
maxconnectID::Int64, updateind::Vector{Int64},
assignment::Vector{Int64})Force localizations linked by assignment to share same the same connectID
SMLMFrameConnection.linkclusters — MethodconnectID, maxconnectID = linkclusters(
connectID::Int64, maxconnectID::Int64,
updateind::Vector{Int64}, assignment::Vector{Int64})Force localizations linked by assignment to share same the same connectID
SMLMFrameConnection.organizeclusters — Methodclusterdata = organizeclusters(smld::BasicSMLD{T,E}) where {T, E<:SMLMData.AbstractEmitter}Organize pre-clusters into a vector indexing distinct clusters.
Description
Pre-clusters in the input smld, as related by their shared integer value of track_id, are organized into a vector of matrices clusterdata. Each index of clusterdata corresponds to a distinct cluster.
SMLMFrameConnection.precluster — Methodsmld_preclustered = precluster(smld::BasicSMLD{T,E},
params::ParamStruct = ParamStruct()) where {T, E<:SMLMData.AbstractEmitter}Cluster localizations in smld based on distance and time thresholds in params.
Description
Localizations in the input structure smld are clustered together based on their spatiotemporal separations. Each localization is linked to those of its params.max_neighbors nearest neighbors, among the localizations of the same dataset in its own frame and the params.max_frame_gap frames before it, that lie within params.max_sigma_dist * (s_i + s_j), where s is a localization's mean of σx and σy. Preclusters are the connected components of these links: their localizations share the same unique integer value for their track_id field. The result does not depend on the order of the input.
Notes
Pre-clustering allows localizations observed in the same frame to be in the same cluster. This is done to prevent exclusion of the "correct" localization from its ideal cluster due to a previously included "incorrect" localization into that cluster.
SMLMFrameConnection.solveLAP — Methodassignment, cost = solveLAP(costmatrix::Matrix{Float32})Solve the linear assignment problem designated by costmatrix.
Description
Solve the linear assignment problem (LAP) defined by costmatrix using the package Hungarian.jl. For now, this method is just a wrapper around Hungarian.jl, however the intention is to add more checks and options to this method in the future.
Citation
David J. Schodt and Keith A. Lidke, "Spatiotemporal Clustering of Repeated Super-Resolution Localizations via Linear Assignment Problem", Frontiers in Bioinformatics, 2021. DOI: 10.3389/fbinf.2021.724325