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_45 | G1_0 | G1_45 R_135 | R_90 | G1_135 | G1_90 G2_0 | G2_45 | B_0 | B_45 G2_135 | G2_90 | B_135 | 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
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 | |
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. |