Skip to main content

C++ implementation of Subset-DIC algorithms with Python bindings

Project description

SubsetDIC

SubsetDIC is a Python package for 2D subset-based digital image correlation (DIC). The performance-critical algorithms are implemented in C++ and exposed to Python through pybind11.

This project is based on the algorithm flow of Ncorr and keeps the original Ncorr reference source under reference_code/ for comparison.

Features

  • Subset-based 2D DIC for grayscale image pairs.
  • C++ core with Python API.
  • ROI-based region extraction.
  • SIFT or manual seed selection.
  • Region-growing DIC propagation.
  • Optional displacement-gradient / strain-field calculation.
  • Example ring and star cases under case/.

Project Layout

SubsetDIC/
|-- src/
|   |-- subsetdic/        # Python API and configuration helpers
|   `-- cpp/              # C++ DIC core and pybind11 bindings
|-- config/
|   `-- default.yaml      # Default DIC parameters
|-- case/
|   |-- ring/             # Example ring images and ROI
|   `-- star/             # Example star displacement images and ROI
|-- tests/
|   |-- test_dic.py       # Synthetic translation integration test
|   `-- run_cases.py      # Run bundled ring/star cases
`-- reference_code/       # Ncorr MATLAB/C++ reference implementation

Installation

Requirements:

  • Python 3.9+
  • CMake 3.21+
  • A C++17 compiler
  • Visual Studio C++ Build Tools on Windows

Install in editable mode:

python -m pip install -e .

This compiles the C++ extension module _core. In editable mode, Python source files are loaded from this repository, while the compiled extension may be installed into your Python environment's site-packages, for example:

C:\Users\<user>\miniconda3\Lib\site-packages\subsetdic\_core.cp312-win_amd64.pyd

After changing files in src/cpp/, run the install command again to rebuild the extension.

Quick Start

import numpy as np
from PIL import Image
from subsetdic import SubsetDIC

ref = np.array(Image.open("case/star/001.bmp")).astype(np.float64)
cur = np.array(Image.open("case/star/002.bmp")).astype(np.float64)
roi = (np.array(Image.open("case/star/003.bmp")) > 128).astype(np.uint8)

dic = SubsetDIC({
    "dic": {
        "radius": 5,
        "spacing": 1,
        "cutoff_diffnorm": 1e-6,
        "cutoff_iteration": 50,
        "subsettrunc": False,
    },
    "seeds": {
        "method": "manual",
        "n_seeds": 1,
        "manual_positions": [(512, 128)],
    },
    "strain": {
        "enabled": True,
        "radius": 15,
    },
    "border": {
        "bcoef": 5,
        "interp": 5,
        "extrap": 5,
    },
})

result = dic.run(ref, cur, roi)

print(result.success)
print(result.u.shape, result.v.shape)
print(result.valid.sum())

API

The main entry point is:

from subsetdic import SubsetDIC

dic = SubsetDIC(config)
result = dic.run(ref_img, def_img, roi_mask=None)

Inputs:

  • ref_img: reference image, 2D array.
  • def_img: deformed/current image, 2D array with the same shape.
  • roi_mask: optional 2D mask. Non-zero pixels are included in DIC.

DicResult fields:

  • success: whether DIC produced a result.
  • u, v: displacement fields.
  • corrcoef: correlation residual field.
  • valid: valid point mask.
  • dudx, dudy, dvdx, dvdy: displacement gradients, available when strain calculation is enabled.
  • points_computed: number of propagated valid points.
  • regions: ROI regions generated from the mask.

Configuration

Default parameters live in config/default.yaml.

dic:
  radius: 20
  spacing: 1
  cutoff_diffnorm: 1.0e-6
  cutoff_iteration: 50
  subsettrunc: true
  direct_seed_grid: false

seeds:
  method: sift
  n_seeds: 1

strain:
  enabled: true
  radius: 5

postprocess:
  enabled: true
  max_iterations: 8
  min_neighbors: 3
  corrcoef_threshold: 2.0

border:
  bcoef: 20
  interp: 20
  extrap: 20

Important parameters:

  • dic.radius: subset radius in pixels.
  • dic.spacing: grid spacing between calculated DIC points.
  • dic.cutoff_diffnorm: IC-GN convergence threshold.
  • dic.cutoff_iteration: maximum IC-GN iterations.
  • dic.subsettrunc: whether to truncate subsets near ROI boundaries.
  • dic.direct_seed_grid: solve each grid point with seed-style local search instead of region-growing propagation. This is slower but more robust for periodic or highly nonuniform displacement fields such as the star case.
  • seeds.method: sift for automatic seeds or manual for fixed positions.
  • seeds.manual_positions: list of (x, y) seed coordinates when using manual seeds.
  • strain.enabled: whether to compute displacement gradients.
  • strain.radius: radius used for gradient fitting.
  • postprocess.enabled: interpolate bad displacement points from neighboring valid points before strain calculation.
  • postprocess.max_iterations: maximum neighbor-growing fill iterations.
  • postprocess.min_neighbors: minimum valid 8-neighbors required to fill a bad point.
  • postprocess.corrcoef_threshold: points with larger correlation residual are treated as bad during interpolation.

You can also override selected DIC parameters when calling run:

result = dic.run(ref, cur, roi, radius=15, spacing=3, compute_strain=False)

Running Tests

Run the synthetic translation test:

python tests\test_dic.py

Expected output includes:

PASSED
All tests passed!

If pytest is installed, the same test can be run with:

python -m pytest -q

Running Example Cases

Run bundled cases:

python tests\run_cases.py

This runs:

  • case/ring
  • case/star

Generated outputs are saved under each case's result/ directory:

  • u.npy
  • v.npy
  • corrcoef.npy
  • valid.npy
  • dudx.npy, dudy.npy, dvdx.npy, dvdy.npy when strain is enabled
  • overview.png

The result/ directories are ignored by Git because they are generated files.

Development Notes

  • Python files under src/subsetdic/ are used directly in editable installs.
  • C++ changes under src/cpp/ require rebuilding with python -m pip install -e ..
  • The extension module is named subsetdic._core.
  • Arrays passed to the C++ core are stored in column-major/Fortran layout to match the Ncorr-style indexing.
  • reference_code/ contains the original Ncorr source used to check algorithm behavior and edge cases.

License

See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

subsetdic-0.1.0.tar.gz (1.9 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

subsetdic-0.1.0-cp312-cp312-win_amd64.whl (329.1 kB view details)

Uploaded CPython 3.12Windows x86-64

subsetdic-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (144.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

subsetdic-0.1.0-cp311-cp311-win_amd64.whl (326.1 kB view details)

Uploaded CPython 3.11Windows x86-64

subsetdic-0.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (145.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

subsetdic-0.1.0-cp310-cp310-win_amd64.whl (325.4 kB view details)

Uploaded CPython 3.10Windows x86-64

subsetdic-0.1.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (143.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

subsetdic-0.1.0-cp39-cp39-win_amd64.whl (326.2 kB view details)

Uploaded CPython 3.9Windows x86-64

subsetdic-0.1.0-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (144.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file subsetdic-0.1.0.tar.gz.

File metadata

  • Download URL: subsetdic-0.1.0.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for subsetdic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3bded7cb7247741fc2f8c3849885e224f14d60dc578ce09a14f756c891a5c74e
MD5 e6ad78b9a624b53f59851807d6b5123c
BLAKE2b-256 8360f477ae3e35808d86eb235065fedd813695f6fe787ad1dc2d5f078151efff

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsetdic-0.1.0.tar.gz:

Publisher: publish-pypi.yml on lbd-hfut/SubsetDIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsetdic-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: subsetdic-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 329.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for subsetdic-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 36f7d04a2ee30e0896cbac9e838ffc396a490e671d03e80065e6db521eeaff03
MD5 b1f53011bbc88e15afd0fce30f10f419
BLAKE2b-256 7a51c7454e24503cfc749b687d0d8640eb6dd667733e3d4b3920828b25568526

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsetdic-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: publish-pypi.yml on lbd-hfut/SubsetDIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsetdic-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for subsetdic-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e7aa650e91eed15065efcabad88820532121ea2cf3bd5d90d9ab9581355bfaff
MD5 8cfdcd736ca1e349ebc6013bb2fd0bde
BLAKE2b-256 9b5d6d55a350448eaa76ac9c3d3e8cd4c337f6318037f3c93cea59a1486d2b8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsetdic-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-pypi.yml on lbd-hfut/SubsetDIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsetdic-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: subsetdic-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 326.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for subsetdic-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 634abb26691aa8123e7e74cb2888c15b21d95101c460d003a0dff0f4490f6784
MD5 811d3360c84337575353ca59c6796a83
BLAKE2b-256 d96849bef1231ef06427778699ab20afd054b125054683c8a5bec33ec642169a

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsetdic-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: publish-pypi.yml on lbd-hfut/SubsetDIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsetdic-0.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for subsetdic-0.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eb516e767cd3d7fcbe5b6e35881c11cc206702bc645242679cb9c97614e4e362
MD5 7ed9037c91ba3c10bfb161037659c655
BLAKE2b-256 33e78bee9cf62fb0c210cd6f804cd19869bf517beb4f680a34d1a17fe7b5ebb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsetdic-0.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-pypi.yml on lbd-hfut/SubsetDIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsetdic-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: subsetdic-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 325.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for subsetdic-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f701b58b774ca24949872857951d311bcc1585a31972fec17c157ce9f565a295
MD5 1d2b3d64bda944d2fffbe96511115711
BLAKE2b-256 17e1e42c2405160754df5ef75c1806c5e543e6b266ba9cf0dc3c1edbe504dc89

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsetdic-0.1.0-cp310-cp310-win_amd64.whl:

Publisher: publish-pypi.yml on lbd-hfut/SubsetDIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsetdic-0.1.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for subsetdic-0.1.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 43927e4c67a007f8f8446281eacd1c1ff66f44ebf632bf053777b0c33dadf4e3
MD5 8f72864197a4ce9c7e9a4535ea7a64b2
BLAKE2b-256 e619f8cfc3daf1afd4adf4bb8a2643cca0ba7168be4fea010ee0e43c9e05f460

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsetdic-0.1.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-pypi.yml on lbd-hfut/SubsetDIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsetdic-0.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: subsetdic-0.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 326.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for subsetdic-0.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3024e5676bab806d2d218873800749dcdf7036e4d3033777241bc483884ff17e
MD5 032b82f13a5139fe273d367e65333690
BLAKE2b-256 960bc0e3560813c7ed716b03febdac86c658e51fc46c553e3ff4d94673f0368b

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsetdic-0.1.0-cp39-cp39-win_amd64.whl:

Publisher: publish-pypi.yml on lbd-hfut/SubsetDIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subsetdic-0.1.0-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for subsetdic-0.1.0-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 da4d83b84a4df37d7c6419fb9ebe44ddedd6b80ff3ad738c7ae9f0599b30ce16
MD5 1449af91620b22e348ff8d811b6f8401
BLAKE2b-256 0c3ed7625908a8ec710d0418262e8838c31c1f08448b1e0e3f3718bade43b93d

See more details on using hashes here.

Provenance

The following attestation bundles were made for subsetdic-0.1.0-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-pypi.yml on lbd-hfut/SubsetDIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page