main¶
Command-line interface entry points.
This module provides the command-line interfaces for the three main tools:
- image-to-stress - Convert photoelastic images to stress maps
- stress-to-image - Generate photoelastic images from stress fields
- demosaic-raw - Process raw polarimetric camera images
main
¶
Functions¶
image_to_stress(params, output_filename=None)
¶
Convert photoelastic images to stress maps.
This function processes raw photoelastic data to recover stress distribution maps using the stress-optic law and polarization analysis.
Args: params (dict): Configuration dictionary containing: - input_filename (str, optional): Path to input image file. If None, raw images are loaded from folderName. - folderName (str): Path to folder containing raw photoelastic images - crop (list, optional): Crop region as [x1, x2, y1, y2] - debug (bool): If True, display all channels for debugging - C (float): Stress-optic coefficient in 1/Pa - thickness (float): Sample thickness in meters - wavelengths (list): List of wavelengths in nanometers - S_i_hat (list): Incoming normalized Stokes vector [S1_hat, S2_hat, S3_hat] output_filename (str, optional): Path to save the output stress map image. If None, the stress map is not saved. Defaults to None. Can also be specified in params.
Returns: numpy.ndarray: 2D array representing the stress map in Pascals.
Notes: - Assumes incoming light is fully S1 polarized - Uses uniform stress-optic coefficient across all wavelengths - Assumes solid sample (NU = 1.0) - Wavelengths are automatically converted from nm to meters
Source code in photoelastimetry/main.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
stress_to_image(params)
¶
Convert stress field data to photoelastic fringe pattern image.
This function loads stress field data, optionally applies Gaussian scattering, computes principal stresses and their orientations, calculates photoelastic retardation and fringe patterns, and saves the resulting visualization.
Args: params (dict): Dictionary containing the following keys: - p_filename (str): Path to the photoelastimetry parameter file - stress_filename (str): Path to the stress field data file - scattering (float, optional): Gaussian filter sigma for scattering simulation. If falsy, no scattering is applied. - t (float): Thickness of the photoelastic material - lambda_light (float): Wavelength of light used in the experiment - C (float): Stress-optic coefficient of the material - output_filename (str, optional): Path for the output image. Defaults to "output.png" if not provided.
Returns: None: The function saves the fringe pattern visualization to a file.
Notes: - The stress field is expected to have components in the order [sigma_xy, sigma_yy, sigma_xx] - Principal stresses are computed using Mohr's circle equations - Isochromatic fringe intensity is calculated using sin²(δ/2) - Isoclinic angle represents the orientation of principal stresses
Source code in photoelastimetry/main.py
cli_image_to_stress()
¶
Command line interface for image_to_stress function.
Source code in photoelastimetry/main.py
cli_stress_to_image()
¶
Command line interface for stress_to_image function.
Source code in photoelastimetry/main.py
demosaic_raw_image(input_file, metadata, output_prefix=None, output_format='tiff')
¶
De-mosaic a raw polarimetric image and save to TIFF stack or individual PNGs.
This function takes a raw image from a polarimetric camera with a 4x4 superpixel pattern and splits it into separate channels for each color and polarization angle.
Args: input_file (str): Path to the raw image file. metadata (dict): Dictionary containing image metadata with keys: - width (int): Image width in pixels - height (int): Image height in pixels - dtype (str, optional): Data type ('uint8' or 'uint16') output_prefix (str, optional): Prefix for output files. If None, uses input filename without extension. Defaults to None. output_format (str, optional): Output format, either 'tiff' for a single TIFF stack or 'png' for individual PNG files. Defaults to 'tiff'.
Returns: numpy.ndarray: De-mosaiced image stack of shape [H, W, 4, 4] where: - H, W are the de-mosaiced dimensions (1/4 of original) - First dimension 4: color channels (R, G1, G2, B) - Second dimension 4: polarization angles (0°, 45°, 90°, 135°)
Notes: - The raw image uses a 4x4 superpixel pattern with interleaved polarization and color filters - Output TIFF stack has shape [H, W, 4, 4] with all channels - Output PNGs create 4 files (one per polarization angle) with shape [H, W, 4] showing all color channels
Source code in photoelastimetry/main.py
cli_demosaic()
¶
Command line interface for de-mosaicing raw polarimetric images.
Source code in photoelastimetry/main.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 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 | |