Contraction Expansion
Contraction and expansion analysis for body movement patterns.
This module provides optimized functions for analyzing contraction and expansion of body configurations in 2D and 3D space. It computes area (2D) or volume (3D) metrics for sets of body points and tracks changes relative to a baseline.
The module uses Numba JIT compilation for performance optimization, making it suitable for real-time motion capture analysis.
Key Features
- Fast area calculation using Shoelace formula (2D)
- Tetrahedron volume calculation using determinants (3D)
- Baseline-relative expansion/contraction indices
- Support for both single-frame and time-series analysis
- Automatic warmup for JIT compilation
Typical Applications
- Dance movement analysis (body expansion/contraction)
- Gesture recognition (hand/arm configurations)
- Sports biomechanics (body positioning)
- Clinical movement assessment
ContractionExpansion
Analyze body movement contraction/expansion patterns.
This class provides a standardized API for computing area (2D) or volume (3D) metrics for body point configurations and tracking expansion/contraction relative to a baseline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode
|
('2D', '3D', None)
|
Analysis mode. If None, auto-detects from data dimensions. |
"2D"
|
baseline_frame
|
int
|
Frame index to use as baseline for time series (default: 0). |
0
|
Examples:
>>> # Create analyzer
>>> ce = ContractionExpansion(mode="2D")
>>>
>>> # Single frame analysis
>>> points_2d = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
>>> result = ce(points_2d)
>>> print(result['metric']) # Area of square
1.0
>>> # Time series analysis
>>> ce_3d = ContractionExpansion(mode="3D", baseline_frame=0)
>>> frames = np.random.randn(100, 4, 3)
>>> result = ce_3d(frames)
>>> print(result['states'][:10]) # First 10 frame states
Source code in pyeyesweb/low_level/contraction_expansion.py
__call__(data)
Analyze movement data using the configured settings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ndarray
|
Either single frame (4, 2) or (4, 3) for 2D/3D points, or time series (n_frames, 4, 2) or (n_frames, 4, 3). |
required |
Returns:
Type | Description |
---|---|
dict
|
For single frame: - 'metric': area or volume value - 'dimension': "2D" or "3D" For time series: - 'metrics': array of area/volume values - 'indices': array of expansion indices relative to baseline - 'states': array of states (-1=contraction, 0=neutral, 1=expansion) - 'dimension': "2D" or "3D" |
Source code in pyeyesweb/low_level/contraction_expansion.py
analyze_movement(data, mode=None, baseline_frame=0)
Analyze body movement contraction/expansion patterns.
This function computes area (2D) or volume (3D) metrics for body point configurations and tracks expansion/contraction relative to a baseline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ndarray
|
Either single frame (4, 2) or (4, 3) for 2D/3D points, or time series (n_frames, 4, 2) or (n_frames, 4, 3). |
required |
mode
|
('2D', '3D', None)
|
Analysis mode. If None, auto-detects from data dimensions. |
"2D"
|
baseline_frame
|
int
|
Frame index to use as baseline for time series (default: 0). |
0
|
Returns:
Type | Description |
---|---|
dict
|
For single frame: - 'metric': area or volume value - 'dimension': "2D" or "3D" For time series: - 'metrics': array of area/volume values - 'indices': array of expansion indices relative to baseline - 'states': array of states (-1=contraction, 0=neutral, 1=expansion) - 'dimension': "2D" or "3D" |
Raises:
Type | Description |
---|---|
ValueError
|
If data shape is invalid or mode doesn't match data dimensions. |
Examples:
>>> # Single frame 2D analysis
>>> points_2d = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
>>> result = analyze_movement(points_2d, mode="2D")
>>> print(result['metric']) # Area of square
1.0
>>> # Time series 3D analysis
>>> frames = np.random.randn(100, 4, 3)
>>> result = analyze_movement(frames, mode="3D", baseline_frame=0)
>>> print(result['states'][:10]) # First 10 frame states
Source code in pyeyesweb/low_level/contraction_expansion.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|