Skip to content

perf(singledic): whole-stack matlab-parallel DIC + feat(proxyncorr): .mat ROI/seed & all ncorr modes - #37

Merged
johnaoga merged 1 commit into
mainfrom
perf/singledic-matlab-parallel-and-proxyncorr-mat-modes
Jun 26, 2026
Merged

johnaoga merged 1 commit into
mainfrom
perf/singledic-matlab-parallel-and-proxyncorr-mat-modes

Conversation

@johnaoga

Copy link
Copy Markdown
Collaborator

Summary

Addresses two issues found while running the apps:

  1. singledic was ~18× slower than xdic (≈280 s/frame vs ≈15 s/frame) even though it tracks a single camera.
  2. proxyncorr couldn't consume xDIC-style .mat ROI/seed sidecars and exposed only a subset of the engine's DIC modes.

1. singledic slowness — fixed

Root cause: SingleDicWorkflow::track() drove the engine through ncorr::NcorrSession::process_frame() one frame at a time. Each call ran plain DIC_analysis({ref, def}), which:

  • re-ran the full automatic seed search from scratch on every frame — the seed computed via loadOrCreateSeed() was never passed to the engine, only stored in the output;
  • had no cross-frame parallelism (serial loop);
  • was not the MATLAB segment-based path the production pipeline uses.

Fix: rewrote track() to mirror StepDWorkflow::runNcorrAnalysis (the proven stepD path), but driven from in-memory cv::Mat frames (no temp-PNG round trip). It now builds one in-memory Image2D stack (ref + all frames), sets update_corrcoef to disable correlation-based reference updates, passes the user seed, and runs a single matlab_DIC_analysis_parallel / _sequential (or the exact_matlab_* variants) pass — honouring config.parallel_processing and config.ncorr_use_exact_matlab.

This brings in all three optimizations the production engine uses: parallel run, segment-based matlab-style, seeded ncorr. Semantically equivalent to the old per-frame loop (each frame still tracked against the fixed reference under NO_UPDATE), just far faster.

2. proxyncorr — .mat ROI/seed + all ncorr modes

  • .mat ROI: --roi/roi= now accepts an image (PNG/BMP/…) or an xDIC .mat mask (refmask var), auto-detected by extension; default ROI now prefers <folder>/roi.mat then roi.png. The --in-memory path is .mat-aware too.
  • .mat seed: --seeds/seeds_file= now accepts a JSON array or a REF_SEED_*.mat (seed_point [x,y]).
  • All ncorr modes via -m/--mode: auto, sequential, parallel (existing) plus matlab-parallel, matlab-sequential, exact-matlab-parallel, exact-matlab-sequential (mode strings normalised; help/config docs updated).
  • CMake: add matio/HDF5 include+link to the proxyncorr target.

Testing

  • Both targets build cleanly with -DBUILD_SINGLEDIC=ON -DBUILD_PROXYNCORR=ON under -Wall -Wextra (no new warnings from changed code).
  • ⚠️ Runtime not verified on this machine: the local OpenCV (4.13) is linked against protobuf 33 while Homebrew has protobuf 35.1, so opencv_dnn fails to load with an ABI mismatch — this breaks every binary equally (the pre-existing cppxdic --help fails identically). It's a local install skew, unrelated to these changes. Reviewer with a working OpenCV/protobuf should smoke-test:
    • singledic on a single-camera trial (compare wall-clock per frame to before),
    • proxyncorr -m matlab-parallel --roi REF_MASK_*.mat --seeds REF_SEED_*.mat.

🤖 Generated with Claude Code

…mat ROI/seed + all ncorr modes

singledic was ~18x slower than xdic (280s vs 15s per frame) because
SingleDicWorkflow::track() drove the engine through
ncorr::NcorrSession::process_frame() one frame at a time. Each call ran
plain DIC_analysis({ref, def}), which re-ran the full automatic seed
search from scratch on every frame (the computed seed was never passed to
the engine), had no cross-frame parallelism, and was not the MATLAB
segment path. Rewrite track() to mirror StepDWorkflow::runNcorrAnalysis:
build one in-memory image stack (ref + all frames), set update_corrcoef
to disable correlation-based reference updates, pass the user seed, and
run a single matlab_DIC_analysis_parallel/_sequential (or exact_matlab_*)
pass honouring config.parallel_processing and ncorr_use_exact_matlab. No
temp-PNG round trip; semantically equivalent (fixed-reference NO_UPDATE)
but seeded, segment-based, and frame-parallel.

proxyncorr: add the ability to read the ROI and seed as xDIC .mat
sidecars (REF_MASK 'refmask' / REF_SEED 'seed_point'), auto-detected by
extension, for both the file-based and --in-memory paths; default ROI now
prefers <folder>/roi.mat then roi.png. Expose all ncorr DIC modes via
-m/--mode: existing auto/sequential/parallel plus matlab-parallel,
matlab-sequential, exact-matlab-parallel, exact-matlab-sequential (mode
strings normalised). Update help/config docs. CMake: add matio/HDF5
include+link to the proxyncorr target.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@johnaoga
johnaoga merged commit 4fe766a into main Jun 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant