SDIC Analysis#
A stereo digital image correlation (SDIC) analysis measures the displacement of a surface, described by a mesh (see Geometry), from the images acquired by one or several cameras (see Imaging Model) at several frames.
SDICAnalysis = reference mesh + displacement of each frame + views (camera, image) of each frame
SDICUnknowns = the optimized frames + the optimized transformations (does not know the analysis)
Pairing = (frame_1, view_1) -> (frame_2, view_2) # Two views whose gray levels are compared
SDICCorrelationTerm(analysis, unknowns, integration_points, pairings) # The pysolvegn.Term (property term)
For a pairing, the gray levels of the material points \(\vec{X}\) of the mesh are compared between the two views:
where \(\vec{u}_1\) and \(\vec{u}_2\) are the (total) displacements of the frames, \(P_1\), \(P_2\) the projections of the cameras and \(I_1\), \(I_2\) the images of the views.
The analysis#
SDICAnalysis: The data of the analysis: the reference mesh, the displacement of its vertices at each frame and the views acquired at each frame, with the structure of the objects shared between the views.
Acquisition setups#
Create a pysdic.SDICAnalysis with the views of the usual acquisition setups. The displacements of the frames
are not set.
create_multicamera_analysis: \(N\) cameras that each acquire their own series of images (view \(i\) of the frame \(f\) =
View(cameras[i], images[i][f])).create_bicamera_analysis: Stereo setup of two cameras that each acquire their own series of images.
create_splitscreen_analysis: \(N\) virtual cameras (stereo mirror adapter) sharing one sensor and one series of images.
create_cordin_analysis: Cordin-like high-speed camera: one sensor seen through \(N\) points of view, with a distortion changing with the frame (rotating mirror).
Note
The cameras (and for pysdic.create_cordin_analysis() the transformations) are shared between the views, not
copied: use pysdic.SDICAnalysis.display_structure() to see which objects are shared, and
pysdic.SDICAnalysis.get_transformation() to access one of them.
Unknowns, pairings and correlation term#
The unknowns of the analysis are optimized with pysolvegn. The vector of unknowns
\(\vec{p} = [\vec{p}_U, \vec{p}_T]\) is made of the total displacements (from the reference mesh, not
increments) of the optimized frames, each one in Fortran order, in the order of the frames, and of the parameters of
the optimized transformations of the cameras, given as (kind, index) (see
pysdic.SDICAnalysis.display_structure()):
measurement: only optimized frames, the cameras are fixed (
SDICUnknowns([1], []));calibration: only optimized transformations, the displacements of all the frames are fixed (
SDICUnknowns([], [("extrinsic", 1)]));joint optimization: both.
The objects of a problem are created in this order:
pysdic.SDICUnknowns, created by the user: the optimized frames and transformations, in their order. As apysdic.Pairing, it does not know the analysis: the analysis validates it (pysdic.SDICAnalysis.validate_unknowns()) and builds the vector \(\vec{p}\) (pysdic.SDICAnalysis.pack_unknowns(),pysdic.SDICAnalysis.unpack_unknowns(),pysdic.SDICAnalysis.apply_unknowns()).pysdic.Pairing: the views to compare.pysdic.SDICCorrelationTerm(analysis, unknowns, integration_points, pairings, ...): compares the gray levels of material points (integration points of the mesh) between the views of the pairings. Itspysolvegn.Termis the propertyterm.
All the objects of a problem (correlation term, temporal regularization, fixed parametrization) receive the same
analysis object and the same unknowns object: pysdic.check_same_problem() checks it (by identity) before
solving. pysolvegn only sees functions: two terms on different unknowns of the same size would be added without
error.
See also
The optimization problems are solved with the Gauss-Newton least squares solver pysolvegn
(pysolve-gn on GitHub, pip install pysolvegn): a pysolvegn.Term
gives the residuals and the Jacobian (mode "rJ") or the gradient and the Hessian (mode "gH") of a part of the
cost, with its weight and its loss function, and several terms with the same unknowns can be combined in the same
problem (e.g. the correlation term and a regularization term). See the documentation of pysolvegn for the solver
options (max_iteration, stopping criteria, damping, …).
import pysolvegn
from pysdic import Pairing, SDICCorrelationTerm, SDICUnknowns
unknowns = SDICUnknowns([1], [("extrinsic", 1)])
pairings = [Pairing.temporal(0, 0, 1), Pairing.temporal(1, 0, 1), Pairing.stereo(0, 0, 1), Pairing.stereo(1, 0, 1)]
correlation = SDICCorrelationTerm(analysis, unknowns, integration_points, pairings,
gl_correction={"mode": "ZNSSD", "scale": 255}, use_cache=True)
result = pysolvegn.solve(terms=[correlation.term], p0=analysis.pack_unknowns(unknowns), max_iteration=20)
analysis.apply_unknowns(unknowns, result.parameters) # Displacement of the frame 1 and extrinsic 1 written in the analysis
# Next frame: new unknowns, new term (same integration points and options)
unknowns_2 = SDICUnknowns([2], [("extrinsic", 1)])
correlation_2 = correlation.with_unknowns(unknowns_2, pairings=pairings_2)
result = pysolvegn.solve(terms=[correlation_2.term], p0=analysis.pack_unknowns(unknowns_2), max_iteration=20)
analysis.apply_unknowns(unknowns_2, result.parameters)
SDICUnknowns: The description of the unknowns of a problem: the optimized frames and transformations (the vector \(\vec{p}\) is built by the analysis).
check_same_problem: Check that the objects of a problem share the same analysis and the same unknowns objects.
Pairing: A link between two views of the analysis (stereo pairing at the same frame, or temporal pairing of the same view at two frames).
SDICCorrelationTerm: The correlation term on the unknowns (modes
"rJ"and"gH", gray level corrections, caches), immutable: new terms withwith_unknowns,with_pairings,with_integration_pointsandwith_options.
Note
An evaluation of the term never modifies the analysis, it reads its current state (displacements of the reference
frames, parameters of the transformations): apply a result with pysdic.SDICAnalysis.apply_unknowns(). A term cannot be
modified: the with_* methods create a new term (new caches, new structures). The objects built on other
unknowns (regularization, parametrization) must be built on the same new unknowns (their own with_unknowns).
Note
With use_cache=True, the term keeps the operators of its last evaluation (returned again for the same
parameters if nothing has changed in the analysis) and the projections of its reference views (views whose frame
and camera have no unknown, projected again only when their displacement or their camera change). Without cache,
everything is computed again at each call. A new term (with_*) starts with empty caches.
Residuals#
The residuals of a pairing at the integration points, and their maps on the images, to check a measure (see also
pysdic.workflows.compute_elements_residual_rms() for the RMS per element):
PairingResiduals: The gray levels and the residuals of the points in the two views of a pairing (frozen dataclass).
compute_residuals: The residuals of a pairing for the current state of the analysis, with or without gray level correction.
compute_pixel_residual_maps: The residuals splatted on the pixels of the two views.
display_residual_maps: Display the residual maps of the two views.
from pysdic import compute_residuals, display_residual_maps
raw = compute_residuals(analysis, Pairing.stereo(1, 0, 1), integration_points) # Current state, raw gray levels
corrected = correlation.compute_residuals() # One PairingResiduals per pairing, correction of the term
display_residual_maps(analysis, corrected[0], fill_radius=2.0)
Gray level corrections#
The gray level corrections are applied by the option gl_correction of pysdic.SDICCorrelationTerm, or directly with the functions below.
The gray levels of the same material point can differ between the two views of a pairing (lighting, exposure,
reflections, …). The corrections remove an affine change of the gray levels, estimated by the mean \(m\) and
the standard deviation \(s\) over groups of integration points:
ZNSSD(zero-mean normalized): both views are normalized, \(g' = \text{scale} \cdot (g - m) / s\).matching: the second view is mapped onto the statistics of the first one, \(g_2' = \text{scale} \cdot ((g_2 - m_2) \, s_1 / s_2 + m_1)\) and \(g_1' = \text{scale} \cdot g_1\).
Warning
With several pairings, the matching correction keeps the contrast of the first view of each pairing: the
pairings no longer have the same weight in the optimization. Prefer ZNSSD when several pairings are combined.
The statistics depend on the gray levels, so on the unknowns. Two derivatives are available for each correction:
approximate (default): \(m\) and \(s\) are considered constant, the Jacobians of the gray levels are only multiplied by the factor of the correction and remain sparse (one point per row).
exact: the derivatives of \(m\) and \(s\) are included. The corrected projections are returned without Jacobians, with a sparse matrix
derivativeto apply to the raw Jacobians of both views.
The groups of points are created with pysdic.compute_gray_level_groups(): a single group (global correction)
or one group per element with the points of its neighborhood (local correction). They only depend on the mesh and on
the integration points: by default a correlation term computes them from gl_correction["neighborhood"], but
they can be computed once and given to several terms with gray_level_groups (e.g. one calibration per frame;
the terms created with with_* share them).
from pysdic import compute_gray_level_groups
groups = compute_gray_level_groups(analysis.mesh, integration_points, neighborhood=1) # Once
correlation = SDICCorrelationTerm(analysis, unknowns, integration_points, pairings,
gl_correction={"mode": "ZNSSD"}, gray_level_groups=groups)
GrayLevelGroups: The groups of integration points used to compute the statistics of the corrections.
compute_gray_level_groups: Compute the groups of points, global or by neighborhood of the elements.
znssd_correction: Normalize the gray levels of both views (ZNSSD), approximate derivative.
znssd_correction_exact: Normalize the gray levels of both views (ZNSSD), exact derivative.
matching_correction: Map the gray levels of the second view onto the first one, approximate derivative.
matching_correction_exact: Map the gray levels of the second view onto the first one, exact derivative.
Note
The non-finite gray levels (points out of the ROI) are ignored by the statistics, and a group with a zero standard deviation gives non-finite corrected values. The exact derivative has \(\sum_G |G|^2\) entries per channel: a global group gives a dense matrix, limited to small numbers of points.
Temporal regularization#
The displacements of the optimized frames can be regularized along the time by penalizing their temporal derivative
of order \(n\) (1 for the velocity, 2 for the acceleration). pysdic.SDICTemporalRegularizationTerm builds
a pysolvegn.Term (property term) on an analysis and a pysdic.SDICUnknowns (zero Jacobian for the
transformations): with the analysis and the unknowns of the correlation term, both terms are combined in the same
problem:
The frames of the regularization are the optimized frames and the fixed frames whose displacement is set (by default), sorted by their
times. The frames without displacement are not given: the step between their neighbors is larger. No displacement is interpolated or extrapolated.The finite difference coefficients \(c_{i,k}\) are computed for the actual times of the frames (Fornberg), with centered stencils inside, the most centered stencils around larger steps and one-sided stencils at the first and last frames (see
pysdic.numeric.assemble_finite_difference_matrix()). Withmax_gap, no stencil spans a larger step.Only the equations involving an optimized frame are kept, including those of the fixed frames next to the optimized ones (e.g. the reference frame).
The weights \(w_e\) of the components and \(\omega_i\) of the frames (
row_weights="time": the duration represented by each frame, so that the cost approximates \(\int \| \vec{u}^{(n)} - \vec{a} \|^2 dt\)) balance the equations.
import pysolvegn
from pysdic import SDICCorrelationTerm, SDICTemporalRegularizationTerm, SDICUnknowns
unknowns = SDICUnknowns(list(range(1, 10)), [])
correlation = SDICCorrelationTerm(analysis, unknowns, integration_points, pairings)
regularization = SDICTemporalRegularizationTerm(analysis, unknowns, order=2, weight=1e-2)
result = pysolvegn.solve([correlation.term, regularization.term], analysis.pack_unknowns(unknowns), max_iteration=20)
analysis.apply_unknowns(unknowns, result.parameters)
softer = regularization.with_options(order=1, weight=1e-1) # A new term, same unknowns
SDICTemporalRegularizationTerm: The term penalizing the temporal derivative of the displacements of the optimized frames (linear residual, constant Jacobian), immutable: new terms with
with_unknownsandwith_options.
Note
The unknowns of the regularization are fixed at its creation: with new unknowns, create a new regularization with
regularization.with_unknowns(unknowns).
Note
The residual is linear in the displacements: its Jacobian is computed once. The one-sided stencils of the first and last frames have larger coefficients than the centered ones, so these frames are more regularized; the coefficients across a larger step are smaller (a displacement change over a longer duration is a smaller derivative).
Fixed parametrization#
The terms always work on the complete vector \(\vec{p}\). A parametrization lets the solver optimize a reduced vector \(\vec{q}\), a selection of \(\vec{p}\) (some vertices and some components of the displacements; all the parameters of the optimized transformations), the other entries keeping their values in the analysis:
pysdic.SDICFixedParametrization is built on the analysis and the pysdic.SDICUnknowns of the problem, and gives the
pysolvegn.Parametrization with its property parametrization. The fixed values \(\vec{p}_{\text{fixed}}\)
are read from the analysis at each call: after a convergence written in the analysis, the same parametrization
can be used again without building it again.
Warning
With a parametrization, always use reparametrized_pack, reparametrized_unpack and
reparametrized_apply on the vectors of the solver: p0 and result.parameters are reduced vectors
\(\vec{q}\). analysis.pack_unknowns, unpack_unknowns and apply_unknowns work on the complete vector
\(\vec{p}\): giving them \(\vec{q}\) raises an error (wrong size) or, worse, misplaces the values if the
sizes happen to match.
Without parametrization |
With a parametrization |
|---|---|
|
|
|
|
|
|
import pysolvegn
from pysdic import SDICFixedParametrization, check_same_problem, compute_supported_vertices
unknowns = SDICUnknowns(frames, [])
correlation = SDICCorrelationTerm(analysis, unknowns, integration_points, pairings)
regularization = SDICTemporalRegularizationTerm(analysis, unknowns, order=2, weight=1e-2)
vertices = compute_supported_vertices(analysis.mesh, integration_points) # Vertices carrying points
parametrization = SDICFixedParametrization(analysis, unknowns, vertices=vertices, components=[0, 1])
check_same_problem([correlation, regularization, parametrization]) # Same analysis, same unknowns
result = pysolvegn.solve([correlation.term, regularization.term], parametrization.reparametrized_pack(),
parametrization=parametrization.parametrization, max_iteration=20)
parametrization.reparametrized_apply(result.parameters) # NOT analysis.apply_unknowns(...)
SDICFixedParametrization: The parametrization optimizing a selection of the unknowns (vertices and components), the other ones read from the analysis at each call.
compute_supported_vertices: The vertices of the elements containing at least one integration point (the other vertices have a zero column in the Jacobian).
Note
Do not confuse pysolvegn.Parametrization (the map \(\vec{q} \mapsto \vec{p}\) of the solver, given by
pysdic.SDICFixedParametrization.parametrization) with pysdic.Parametrization (the parameters of a
transformation of a camera).