Skip to content

Commit fcce15a

Browse files
Copilotalexlib
andcommitted
Integrate synimage module into openpiv.tools
Co-authored-by: alexlib <[email protected]>
1 parent b97edf8 commit fcce15a

File tree

8 files changed

+1217
-0
lines changed

8 files changed

+1217
-0
lines changed
101 KB
Binary file not shown.

openpiv/synimage/Synthetic_Image_Generator_examples.ipynb

Lines changed: 367 additions & 0 deletions
Large diffs are not rendered by default.

openpiv/synimage/__init__.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
"""Synthetic Image Generator Module for OpenPIV.
2+
3+
This module provides tools to generate synthetic PIV images for testing and validation.
4+
"""
5+
6+
from .synimagegen import (
7+
continuous_flow_field,
8+
create_synimage_parameters,
9+
generate_particle_image,
10+
)
11+
12+
__all__ = [
13+
'continuous_flow_field',
14+
'create_synimage_parameters',
15+
'generate_particle_image',
16+
'synimagegen',
17+
]
18+
19+
20+
def synimagegen(
21+
image_size=128,
22+
dt=0.1,
23+
x_bound=(0, 1),
24+
y_bound=(0, 1),
25+
den=0.008,
26+
par_diam_mean=15 ** (1.0 / 2),
27+
bit_depth=8,
28+
):
29+
"""Generate a pair of synthetic PIV images with default parameters.
30+
31+
This is a convenience function that creates synthetic PIV image pairs
32+
with sensible defaults for testing and validation.
33+
34+
Parameters
35+
----------
36+
image_size : int, optional
37+
Size of the square image in pixels (default: 128)
38+
dt : float, optional
39+
Synthetic time difference between images (default: 0.1)
40+
x_bound : tuple of floats, optional
41+
X-axis boundaries (default: (0, 1))
42+
y_bound : tuple of floats, optional
43+
Y-axis boundaries (default: (0, 1))
44+
den : float, optional
45+
Particle density (default: 0.008)
46+
par_diam_mean : float, optional
47+
Mean particle diameter in pixels (default: sqrt(15))
48+
bit_depth : int, optional
49+
Bit depth of output images (default: 8)
50+
51+
Returns
52+
-------
53+
tuple
54+
(image_a, image_b) - A tuple of two numpy arrays representing
55+
the synthetic PIV image pair
56+
57+
Examples
58+
--------
59+
>>> from openpiv.tools import synimage
60+
>>> image_a, image_b = synimage.synimagegen(128)
61+
>>> print(image_a.shape)
62+
(128, 128)
63+
"""
64+
# Convert scalar to tuple if needed
65+
if isinstance(image_size, int):
66+
img_size = (image_size, image_size)
67+
else:
68+
img_size = image_size
69+
70+
# Create synthetic image parameters
71+
(
72+
cff,
73+
conversion_value,
74+
x1,
75+
y1,
76+
U_par,
77+
V_par,
78+
par_diam1,
79+
par_int1,
80+
x2,
81+
y2,
82+
par_diam2,
83+
par_int2,
84+
) = create_synimage_parameters(
85+
input_data=None,
86+
x_bound=x_bound,
87+
y_bound=y_bound,
88+
image_size=img_size,
89+
path=None,
90+
inter=False,
91+
den=den,
92+
per_loss_pairs=2,
93+
par_diam_mean=par_diam_mean,
94+
par_diam_std=1.5,
95+
par_int_std=0.25,
96+
dt=dt,
97+
)
98+
99+
# Generate the two images
100+
image_a = generate_particle_image(
101+
img_size[1], img_size[0], x1, y1, par_diam1, par_int1, bit_depth
102+
)
103+
104+
image_b = generate_particle_image(
105+
img_size[1], img_size[0], x2, y2, par_diam2, par_int2, bit_depth
106+
)
107+
108+
return image_a, image_b

openpiv/synimage/simple_synthetic_image_demo.ipynb

Lines changed: 185 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)