Sampling moire analysis for full-field micro-displacement and micro-strain measurement from grating images.
Project description
moirestrain
NumPy-first tools for phase-shifted sampling moire analysis of periodic
grating images. moirestrain targets full-field micro-displacement and
micro-strain measurement from reference/deformed grid images.
moirestrain estimates phase fields from periodic grating images and converts
reference/deformed phase differences into displacement and small-strain fields.
The current high-level workflow focuses on two-dimensional square-marker grid
targets, such as regularly spaced black squares on a white background.
Highlights
- Generate phase-shifted sampling moire images from a single grating image.
- Estimate wrapped phase with a phase-shifting formula.
- Calculate displacement from reference/deformed phase difference.
- Analyze square-grid targets in both x/y directions.
- Output
u,v,exx,eyy, andgamma_xyfields. - Detect partial grating ROIs inside larger images.
- Rectify tilted planar grating regions from four corner points.
- Save analysis arrays, valid ROI masks, and PNG summaries.
The numerical core is NumPy-based. Runtime dependencies also include
imageio and matplotlib for CLI image I/O and PNG reporting. scikit-image
is used only by optional examples and development tests.
Results
Partial-Grid Strain Recovery
This example detects a square-grid patch inside a larger image, crops the valid ROI, and compares measured strain against the known synthetic truth.
ROI Detection In A Full Image
The same workflow also reports the full image, grating-energy map, detected mask, cropped ROI, and strain field.
Natural-Image Background
This example places a square-grid strain target on a natural-image background, detects the grid ROI, rectifies the patch, and outputs the measured strain fields.
Benchmark
The benchmark compares measured fields with ground truth and sweeps target period and strain presets.
Installation
For local development:
poetry install
Run tests:
poetry run pytest
Build distributions:
poetry build
Quick Start
from moirestrain import analyze_grid, recommended_strain_smoothing_window
period = 16
strain_window = recommended_strain_smoothing_window(period, cycles=3)
result = analyze_grid(
reference_image,
deformed_image,
period=period,
strain_smooth_window=strain_window,
)
u = result.x.displacement
v = result.y.displacement
exx = result.strain.exx
eyy = result.strain.eyy
gamma_xy = result.strain.gamma_xy
For one-direction grating analysis:
from moirestrain import phase_shifted_sampling_moire
result = phase_shifted_sampling_moire(
reference_image,
deformed_image,
period=8,
axis="x",
grating_pitch=8.0,
)
u = result.displacement
CLI
Analyze a manually cropped square-grid ROI:
moirestrain analyze-grid ref.png def.png \
--period 16 \
--roi y0,x0,y1,x1 \
--out result.npz \
--figure result.png
Detect the dominant grating ROI automatically:
moirestrain analyze-grid ref.png def.png \
--period 16 \
--auto-roi \
--out result.npz \
--figure result.png
Create a four-corner calibration, rectify an image pair, then analyze:
moirestrain make-calibration \
--image-points x0,y0,x1,y1,x2,y2,x3,y3 \
--output-shape 240,320 \
--period 16 \
--out calibration.json
moirestrain rectify-pair ref.png def.png \
--calibration calibration.json \
--reference-out rectified_ref.npy \
--deformed-out rectified_def.npy \
--metadata-out rectification_metadata.json
moirestrain analyze-grid ref.png def.png \
--period 16 \
--calibration calibration.json \
--out result.npz \
--figure result.png
If physical dimensions are known, pass --world-points and --unit to
make-calibration. The analysis output then includes u_physical,
v_physical, pixel_spacing, and physical-coordinate strain fields.
Use --no-figure for batch jobs that only need .npz arrays.
Examples
Generate synthetic data, run benchmarks, and build figures:
PYTHONPATH=src python examples/benchmark_microstrain.py
PYTHONPATH=src python examples/benchmark_sweep.py
PYTHONPATH=src python examples/partial_grid_detection_analysis.py
PYTHONPATH=src python examples/skimage_natural_grating_strain.py
Runnable learning-oriented workflows are under tutorials/:
PYTHONPATH=src python tutorials/01_square_grid_analysis.py
PYTHONPATH=src python tutorials/02_partial_grid_detection.py
PYTHONPATH=src python tutorials/03_four_corner_rectification.py
Other examples:
PYTHONPATH=src python examples/generate_experiment.py
PYTHONPATH=src python examples/microstrain_square_grid.py
PYTHONPATH=src python examples/strain_distribution.py
PYTHONPATH=src python examples/perspective_rectification.py
Build documentation assets and Sphinx HTML:
PYTHONPATH=src python scripts/build_docs_assets.py
poetry run sphinx-build -b html docs docs/_build/html
Notes For Experiments
- Use a camera-space grid pitch around
12-16 pxor larger when possible. - Square-marker targets contain strong harmonics; strain estimation needs smoothing before differentiation.
- Evaluate and display only a valid inner ROI near image boundaries.
- For tilted planar targets, rectify from four corner points before analysis.
- For real images, check illumination, blur, noise, grid pitch calibration, and registration between reference/deformed frames.
Citation
License
MIT License. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moirestrain-0.1.0.tar.gz.
File metadata
- Download URL: moirestrain-0.1.0.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa7b2e01370594c0b56eb21422c89e7583da37c2b826e918eb7bdfd5a160247d
|
|
| MD5 |
0c21df06717e3fb50a2242336362276e
|
|
| BLAKE2b-256 |
424f8a39d33611ceda0c08d0227d3675ac0c31cda5e8bd475dcdfaad2dacaedb
|
Provenance
The following attestation bundles were made for moirestrain-0.1.0.tar.gz:
Publisher:
workflow.yml on kevin-tofu/moirestrain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moirestrain-0.1.0.tar.gz -
Subject digest:
fa7b2e01370594c0b56eb21422c89e7583da37c2b826e918eb7bdfd5a160247d - Sigstore transparency entry: 1549412031
- Sigstore integration time:
-
Permalink:
kevin-tofu/moirestrain@a39a3e49b7520eac2df5cb7d6999221c70f441fb -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/kevin-tofu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@a39a3e49b7520eac2df5cb7d6999221c70f441fb -
Trigger Event:
release
-
Statement type:
File details
Details for the file moirestrain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: moirestrain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78b73f27195c195cbbc9d4e985b7f4746b2e69a14f10d3c62387a7c1842b0efc
|
|
| MD5 |
e9d2d44982f4814f829f7f3d4ea622f9
|
|
| BLAKE2b-256 |
ba5a99f4c7f3cf6eb86fd9b0d977b03c2a46063ffc74c624191d15f71c19bb4a
|
Provenance
The following attestation bundles were made for moirestrain-0.1.0-py3-none-any.whl:
Publisher:
workflow.yml on kevin-tofu/moirestrain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moirestrain-0.1.0-py3-none-any.whl -
Subject digest:
78b73f27195c195cbbc9d4e985b7f4746b2e69a14f10d3c62387a7c1842b0efc - Sigstore transparency entry: 1549412279
- Sigstore integration time:
-
Permalink:
kevin-tofu/moirestrain@a39a3e49b7520eac2df5cb7d6999221c70f441fb -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/kevin-tofu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@a39a3e49b7520eac2df5cb7d6999221c70f441fb -
Trigger Event:
release
-
Statement type: