io¶
Input/output operations for images and data.
This module handles reading and writing of image files, raw camera data, and parameter files for photoelastic analysis workflows.
io
¶
Functions:¶
list_supported_bayer_pixel_formats()
¶
Return the supported Bayer pixelFormat descriptors keyed by PFNC code.
split_channels(data)
¶
Splits the data into its respective polarisation channels. Each superpixel is 4x4 pixels, and the channels are arranged in the following order:
R_0 | R_135 | G1_0 | G1_135 R_45 | R_90 | G1_45 | G1_90 G2_0 | G2_135 | B_0 | B_135 G2_45 | G2_90 | B_45 | B_90
Source code in photoelastimetry/io.py
collapse_duplicate_green_channel(data)
¶
Convert demosaiced RGGB data to the canonical RGB channel set.
Source code in photoelastimetry/io.py
save_image(filename, data, metadata={})
¶
Save image data to a file in various formats.
This function saves image data to disk in one of several supported formats, automatically determining the format from the file extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the output file. The file extension determines the format. Supported extensions: .npy, .raw, .png, .jpg, .jpeg, .tiff, .tif |
required |
data
|
ndarray
|
Image data to save. The data will be cast to the appropriate dtype based on the file format (uint8 for .png/.jpg, uint16 for .tiff, etc.) |
required |
metadata
|
dict
|
Dictionary containing metadata about the image. For .raw format, must contain a "dtype" key specifying the data type to use when saving. Default is empty. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file extension is not one of the supported formats. |
Notes
- .npy files preserve the original data type and shape
- .raw files are saved as binary with dtype specified in metadata
- .png and .jpg files convert data to uint8
- .tiff/.tif files convert data to uint16
- matplotlib is used for .png and .jpg formats
- tifffile library is used for .tiff/.tif formats
Examples:
>>> data = np.random.randint(0, 255, (100, 100), dtype=np.uint8)
>>> metadata = {"dtype": "uint8"}
>>> save_image("output.png", data, metadata)
Source code in photoelastimetry/io.py
load_image(filename, metadata=None)
¶
Load image data from a file in various formats.
This function loads image data from disk in one of several supported formats, automatically determining the format from the file extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the input file. The file extension determines the format. Supported extensions: .npy, .raw, .png, .jpg, .jpeg, .tiff, .tif. A raw recording directory containing recordingMetadata.json is also supported. |
required |
metadata
|
dict
|
Dictionary containing metadata about the image. For .raw format, must contain "width", "height", and "dtype" keys specifying the image dimensions and data type. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Loaded image data. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file extension is not one of the supported formats. |
Notes
- .npy files preserve the original data type and shape
- .raw files are read as binary with dtype and shape specified in metadata
- .png and .jpg files are loaded as uint8 arrays
- .tiff/.tif files are loaded as uint16 arrays
- matplotlib is used for .png and .jpg formats
- tifffile library is used for .tiff/.tif formats
Examples:
>>> metadata = {"width": 100, "height": 100, "dtype": "uint8"}
>>> data = load_image("input.raw", metadata)
Source code in photoelastimetry/io.py
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 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 | |
bin_image(data, binning)
¶
Bin the image by the specified factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input image data to be binned. |
required |
binning
|
int
|
Binning factor. The image dimensions will be reduced by this factor. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Binned image data. |