Skip to main content

Sampling moire analysis for full-field micro-displacement and micro-strain measurement from grating images.

Project description

moirestrain

Python tests Documentation Status PyPI version Python versions License: MIT

Current version: 0.1.1

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, and gamma_xy fields.
  • 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.

partial grid measured true strain comparison

ROI Detection In A Full Image

The same workflow also reports the full image, grating-energy map, detected mask, cropped ROI, and strain field.

partial grid detection analysis

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.

natural image grid strain analysis

Benchmark

The benchmark compares measured fields with ground truth and sweeps target period and strain presets.

microstrain benchmark sweep

Installation

Install the released package from PyPI with pip:

pip install moirestrain

Or add it to a Poetry project:

poetry add moirestrain

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 px or 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


Download files

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

Source Distribution

moirestrain-0.1.1.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

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

moirestrain-0.1.1-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file moirestrain-0.1.1.tar.gz.

File metadata

  • Download URL: moirestrain-0.1.1.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moirestrain-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d94c288a4577d2ab40d552dcd8f0a697fa1b48fadbe9a8073888215fcd168c99
MD5 ce72ec941c789529c16237b29ecf2513
BLAKE2b-256 aa8e2e4177218436c46dfd7ea25c3d18780d5b3690171831c990b6da0a23abc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for moirestrain-0.1.1.tar.gz:

Publisher: workflow.yml on kevin-tofu/moirestrain

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

File details

Details for the file moirestrain-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: moirestrain-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moirestrain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f72bbb275c6805768cbca8bb1824b4d8c35505a0199310d69b9cefb8b03b76f
MD5 74007383e8dea6bdda90b5cfa838c799
BLAKE2b-256 b594ae98b084585c256df82270b508c4e67b1512dd7f3f440b2e0af768259c58

See more details on using hashes here.

Provenance

The following attestation bundles were made for moirestrain-0.1.1-py3-none-any.whl:

Publisher: workflow.yml on kevin-tofu/moirestrain

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