optimiser.intensity¶
Intensity-based pixel-wise stress inversion.
This module provides an alternative approach that works directly with raw polarization intensities rather than Stokes components. This can be beneficial when raw intensities provide more reliable measurements.
Key Functions¶
predict_intensity()- Forward model for intensity predictionrecover_stress_map_intensity()- Main function for intensity-based stress recoverycompare_stokes_vs_intensity()- Compare Stokes and intensity-based methods
intensity
¶
Intensity-based stress measurement using raw polarimetric intensities.
This module implements stress tensor recovery by optimizing directly on raw polarization intensity measurements rather than normalized Stokes components. This approach:
- Avoids information loss from normalization
- Eliminates angle-wrapping ambiguities from Stokes → angle conversion
- Allows proper statistical modeling of detector noise (Poisson + Gaussian)
- Enables joint calibration of instrument parameters
- Provides more robust inversion near degenerate points (low retardance)
The forward model predicts intensity for each analyzer angle and wavelength from the stress tensor via Mueller/Jones calculus.
Functions¶
predict_intensity(sigma_xx, sigma_yy, sigma_xy, C, nu, L, wavelength, analyzer_angles, S_i_hat, I0=1.0)
¶
Predict intensity measurements for different analyzer angles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma_xx
|
float
|
Normal stress component in x direction (Pa). |
required |
sigma_yy
|
float
|
Normal stress component in y direction (Pa). |
required |
sigma_xy
|
float
|
Shear stress component (Pa). |
required |
C
|
float
|
Stress-optic coefficient (1/Pa). |
required |
nu
|
float
|
Solid fraction (use 1.0 for solid samples). |
required |
L
|
float
|
Sample thickness (m). |
required |
wavelength
|
float
|
Wavelength of light (m). |
required |
analyzer_angles
|
array - like
|
Analyzer angles in radians [0, π/4, π/2, 3π/4]. |
required |
S_i_hat
|
array - like
|
Incoming normalized Stokes vector [S1_hat, S2_hat, S3_hat]. |
required |
I0
|
float
|
Incident intensity (default: 1.0). |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
intensities |
ndarray
|
Predicted intensities for each analyzer angle. |
Notes
The intensity at analyzer angle α is computed using Mueller calculus: I(α) = [1, cos(2α), sin(2α), 0] @ M_sample @ S_in
where M_sample is the Mueller matrix of the birefringent sample.
Source code in photoelastimetry/optimiser/intensity.py
compute_intensity_residual(stress_params, I_measured, wavelengths, C_values, nu, L, analyzer_angles, S_i_hat, I0=1.0, weights=None)
¶
Compute residual between measured and predicted intensities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stress_params
|
array - like
|
Stress tensor components [sigma_xx, sigma_yy, sigma_xy]. |
required |
I_measured
|
ndarray
|
Measured intensities, shape (n_wavelengths, n_angles). Typically (3, 4) for RGB × 4 analyzer angles. |
required |
wavelengths
|
array - like
|
Wavelengths for each channel (m). |
required |
C_values
|
array - like
|
Stress-optic coefficients for each channel (1/Pa). |
required |
nu
|
float
|
Solid fraction (use 1.0 for solid samples). |
required |
L
|
float
|
Sample thickness (m). |
required |
analyzer_angles
|
array - like
|
Analyzer angles in radians [0, π/4, π/2, 3π/4]. |
required |
S_i_hat
|
array - like
|
Incoming normalized Stokes vector [S1_hat, S2_hat, S3_hat]. |
required |
I0
|
float
|
Incident intensity (default: 1.0). |
1.0
|
weights
|
ndarray
|
Weights for residuals, shape matching I_measured. If None, uniform weighting is used. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
residual |
ndarray
|
Flattened array of weighted residuals. |
Source code in photoelastimetry/optimiser/intensity.py
recover_stress_tensor_intensity(I_measured, wavelengths, C_values, nu, L, S_i_hat, analyzer_angles=None, I0=1.0, weights=None, initial_guess=None, method='lm', bounds=None)
¶
Recover stress tensor from raw intensity measurements.
This function inverts the forward model to find the stress tensor that best explains the measured intensities across all wavelengths and analyzer angles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
I_measured
|
ndarray
|
Measured intensities, shape (n_wavelengths, n_angles). Typically (3, 4) for RGB × 4 analyzer angles [0°, 45°, 90°, 135°]. |
required |
wavelengths
|
array - like
|
Wavelengths for R, G, B channels (m). |
required |
C_values
|
array - like
|
Stress-optic coefficients for R, G, B channels (1/Pa). |
required |
nu
|
float
|
Solid fraction (use 1.0 for solid samples). |
required |
L
|
float
|
Sample thickness (m). |
required |
analyzer_angles
|
array - like
|
Analyzer angles in radians. Default: [0, π/4, π/2, 3π/4]. |
None
|
S_i_hat
|
array - like
|
Incoming normalized Stokes vector [S1_hat, S2_hat, S3_hat]. |
required |
I0
|
float
|
Incident intensity for normalization (default: 1.0). |
1.0
|
weights
|
ndarray
|
Weights for residuals, shape matching I_measured. For Poisson noise, use weights[c, i] = 1/sqrt(I_measured[c, i]). If None, uniform weighting is used. |
None
|
initial_guess
|
array - like
|
Initial guess for stress tensor [sigma_xx, sigma_yy, sigma_xy]. If None, computed from Stokes-based quick estimate. |
None
|
method
|
str
|
Optimization method: 'lm' (Levenberg-Marquardt, default), 'trf', 'dogbox', or 'nelder-mead'. |
'lm'
|
bounds
|
tuple of array-like
|
Lower and upper bounds for parameters (lower, upper). Each should be array of length 3 for [sigma_xx, sigma_yy, sigma_xy]. Default: (-1e9, 1e9) Pa for all components. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
stress_tensor |
ndarray
|
Recovered stress tensor components [sigma_xx, sigma_yy, sigma_xy]. |
success |
bool
|
Whether optimization was successful. |
result |
OptimizeResult
|
Full optimization result object. |
Notes
This method is generally more accurate than Stokes-based inversion when: - High precision is required - Working near zero retardance (degenerate cases) - Principal stress axes aligned with incident polarization - Want to model detector noise properly (Poisson statistics)
For typical usage, the Stokes-based method is faster and often sufficient.
Examples:
>>> # Typical usage with 3 wavelengths, 4 analyzer angles
>>> I_measured = np.array([[I0_R, I45_R, I90_R, I135_R],
... [I0_G, I45_G, I90_G, I135_G],
... [I0_B, I45_B, I90_B, I135_B]])
>>> wavelengths = np.array([650e-9, 550e-9, 450e-9])
>>> C_values = np.array([2e-12, 2e-12, 2e-12])
>>> stress, success, result = recover_stress_tensor_intensity(
... I_measured, wavelengths, C_values, nu=1.0, L=0.01
... )
Source code in photoelastimetry/optimiser/intensity.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
recover_stress_map_intensity(image_stack, wavelengths, C_values, nu, L, S_i_hat, analyzer_angles=None, I0=1.0, use_poisson_weights=True, initial_guess_method='uniform', method='nelder-mead', initial_guess_map=None, n_jobs=-1)
¶
Recover full 2D stress tensor map from raw intensity image stack using intensity method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_stack
|
ndarray
|
Image stack of shape [H, W, n_wavelengths, n_angles] where: - H, W are image dimensions - n_wavelengths is number of color channels (typically 3 for RGB) - n_angles is number of polarization analyzer angles (typically 4) |
required |
wavelengths
|
array - like
|
Wavelengths for each channel (m). |
required |
C_values
|
array - like
|
Stress-optic coefficients for each channel (1/Pa). |
required |
nu
|
float or ndarray
|
Solid fraction. Use 1.0 for solid samples. Can be scalar or array matching image dimensions [H, W]. |
required |
L
|
float
|
Sample thickness (m). |
required |
analyzer_angles
|
array - like
|
Analyzer angles in radians. Default: [0, π/4, π/2, 3π/4]. |
None
|
S_i_hat
|
array - like
|
Incoming normalized Stokes vector [S1_hat, S2_hat, S3_hat]. |
required |
I0
|
float
|
Reference incident intensity (default: 1.0). |
1.0
|
use_poisson_weights
|
bool
|
Whether to use Poisson noise weighting (weight ~ 1/sqrt(I)). Default: True. |
True
|
initial_guess_method
|
str
|
Method for initial guess: 'stokes' (default) uses Stokes-based solver, 'zero' uses zeros, 'uniform' uses small uniform stress. |
'uniform'
|
method
|
str
|
Optimization method: 'lm' (default), 'trf', 'dogbox', or 'nelder-mead'. |
'nelder-mead'
|
initial_guess_map
|
ndarray
|
Initial guess stress map [H, W, 3]. Overrides initial_guess_method. |
None
|
n_jobs
|
int
|
Number of parallel jobs. -1 uses all available cores (default: -1). |
-1
|
Returns:
| Name | Type | Description |
|---|---|---|
stress_map |
ndarray
|
Array of shape [H, W, 3] containing [sigma_xx, sigma_yy, sigma_xy] in Pa. |
success_map |
ndarray
|
Boolean array of shape [H, W] indicating successful convergence. |
Notes
This is the main function for generating stress maps using intensity-based inversion. It processes each pixel independently and can run in parallel.
For most applications, this method is slower but more accurate than the Stokes-based method, especially near degenerate points.
Source code in photoelastimetry/optimiser/intensity.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
compare_stokes_vs_intensity(image_stack, wavelengths, C_values, nu, L, S_i_hat, analyzer_angles=None, true_stress=None)
¶
Compare Stokes-based and intensity-based inversion methods.
This utility function runs both methods on the same data and provides comparison metrics. Useful for validation and understanding trade-offs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_stack
|
ndarray
|
Image stack [H, W, n_wavelengths, n_angles]. |
required |
wavelengths
|
array - like
|
Wavelengths for each channel (m). |
required |
C_values
|
array - like
|
Stress-optic coefficients (1/Pa). |
required |
nu
|
float or ndarray
|
Solid fraction. |
required |
L
|
float
|
Sample thickness (m). |
required |
analyzer_angles
|
array - like
|
Analyzer angles in radians. |
None
|
S_i_hat
|
array - like
|
Incoming normalized Stokes vector [S1_hat, S2_hat, S3_hat]. |
required |
true_stress
|
ndarray
|
Ground truth stress field [H, W, 3] for validation. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
results |
dict
|
Dictionary containing: - 'stokes_stress': Stokes solver result [H, W, 3] - 'intensity_stress': Intensity solver result [H, W, 3] - 'stokes_success_rate': Convergence rate for Stokes - 'intensity_success_rate': Convergence rate for intensity - 'stokes_residual': Mean residual for Stokes - 'intensity_residual': Mean residual for intensity - 'stokes_error': RMSE vs truth (if provided) - 'intensity_error': RMSE vs truth (if provided) - 'runtime_stokes': Execution time for Stokes - 'runtime_intensity': Execution time for intensity |
Source code in photoelastimetry/optimiser/intensity.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |