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¶
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
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 |
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
184 185 186 187 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 | |
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. |