Commit 2509cde
Add
* Update __init__.py
* add `lazy_imread` function that accepts list of images
This commit changes image reading to be more flexible: input can be a single path, a glob pattern or a list of image paths. Images of different sizes are stacked using dask delayed arrays. (Mostly inspired by napari's own default implementation.)
Previous implementation only allowed for a glob pattern when loading multiple images. This has the disadvantage that files with different extensions cannot be loaded.
Fixes issue #3160 with multiple images that have different extensions.
* Update lazy_imread
Simplifies and unifies image reading from folders and lists by reintroducing lazy_imread function and updating read_images to handle both cases. Improves extension filtering, error handling, and metadata construction.
* Update test_reader.py
* Update _reader.py
* Refactor image reading and error handling in _reader.py
Improved error handling for image reading by raising an OSError when images cannot be read. Refactored Dask delayed lambda usage for image normalization, and simplified file path sorting and variable naming for clarity and consistency.
* Improve image and annotation file handling in reader
Refactored get_folder_parser to process .h5 files directly in the loop and improved error messages. Enhanced read_images to raise errors for missing or multiple matches, ensuring only a single image is processed as expected.
* Refactor lazy image reading and normalization logic
Introduces helper functions for image reading and normalization, improving clarity and maintainability. Refactors the lazy_imread function to use these helpers and partial application, and makes minor docstring and metadata improvements throughout the file.
* Improve error handling and variable naming in reader
Replaces silent failures with explicit exceptions in lazy_imread, clarifies shape ordering for OpenCV streams, and renames variables for consistency. The return value of read_video now includes an additional 'image' string for clarity.
* Clarify error message for multiple image matches
Improved the ValueError message in read_images to better explain the expectation when multiple files match a pattern for non-list path inputs.
* Expand and refactor video and image reader tests
Replaces and extends previous video-related tests with more comprehensive coverage, including property checks, frame reading, error handling, and output structure validation. Adds new tests for image reading, metadata ordering, grayscale/RGBA handling, and lazy loading behaviors.
* Refactor lazy_imread and improve metadata handling
Renamed internal variables in lazy_imread for clarity and updated delayed array creation for better readability. Enhanced metadata returned by _load_superkeypoints_diagram to include diagram name. Updated test comment for cv2.imwrite to clarify behavior.
* Refactor image reading logic and improve path handling
Introduces _expand_image_paths to robustly resolve input paths, directories, and globs into valid image files. Replaces lazy_imread with _lazy_imread, updating logic for Dask-based lazy loading and stacking. Refactors read_images to use the new path expansion and loading functions, improving consistency and error handling for single and multiple image inputs.
* Add tests for mixed image extensions and glob patterns
Introduces tests to verify that the image reader correctly handles lists, tuples, and glob patterns with mixed file extensions, ensuring only supported formats are included and order is preserved.
* Update src/napari_deeplabcut/_reader.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update src/napari_deeplabcut/_reader.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test_reader.py
* Refactor lazy image reading and update tests
Refactored _lazy_imread to pass first_shape and first_dtype to make_delayed_array for improved clarity and consistency. Removed unnecessary import and assertion in test_reader, and ensured tests properly check unsupported image extensions.
* Fix image extension filtering and update tests
Improved directory image filtering in _expand_image_paths to only include files with supported extensions. Updated tests to use a fake unsupported extension instead of .tif, ensuring unsupported files are correctly ignored.
* Use is_numeric_dtype for image_paths type check (pandas >=3.0)
Replaces np.issubdtype with pandas' is_numeric_dtype to more robustly check if image_paths is numeric in read_hdf. This improves compatibility with different pandas index types.
* Update _reader.py
* Revert "Update _reader.py"
This reverts commit 8c276c5.
* Update _reader.py
* Revert - handle missing superkeypoints diagram with FileNotFoundError again
Wraps the image loading in a try-except block and raises a FileNotFoundError with a descriptive message if the diagram for the specified super_animal is not found.
* Fix directory extension check and update test variable names for clarity
---------
Co-authored-by: Jaap de Ruyter <deruyter92@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>lazy_imread function to read list of images with mismatched extensions (#154)1 parent f8bf1d3 commit 2509cde
2 files changed
+489
-50
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
61 | 71 | | |
62 | 72 | | |
63 | 73 | | |
64 | | - | |
65 | 74 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
72 | 78 | | |
73 | | - | |
| 79 | + | |
74 | 80 | | |
75 | | - | |
| 81 | + | |
| 82 | + | |
76 | 83 | | |
77 | 84 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
81 | 90 | | |
82 | 91 | | |
83 | 92 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 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 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 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 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
96 | 269 | | |
97 | 270 | | |
98 | 271 | | |
99 | | - | |
100 | | - | |
| 272 | + | |
| 273 | + | |
101 | 274 | | |
102 | 275 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 276 | + | |
110 | 277 | | |
111 | 278 | | |
| 279 | + | |
112 | 280 | | |
113 | 281 | | |
114 | 282 | | |
| |||
175 | 343 | | |
176 | 344 | | |
177 | 345 | | |
| 346 | + | |
178 | 347 | | |
179 | 348 | | |
180 | 349 | | |
| |||
196 | 365 | | |
197 | 366 | | |
198 | 367 | | |
| 368 | + | |
199 | 369 | | |
200 | 370 | | |
201 | 371 | | |
| |||
228 | 398 | | |
229 | 399 | | |
230 | 400 | | |
231 | | - | |
| 401 | + | |
232 | 402 | | |
233 | 403 | | |
234 | 404 | | |
| |||
254 | 424 | | |
255 | 425 | | |
256 | 426 | | |
| 427 | + | |
257 | 428 | | |
258 | 429 | | |
259 | 430 | | |
| |||
297 | 468 | | |
298 | 469 | | |
299 | 470 | | |
300 | | - | |
| 471 | + | |
| 472 | + | |
301 | 473 | | |
302 | 474 | | |
303 | 475 | | |
304 | 476 | | |
305 | 477 | | |
306 | | - | |
| 478 | + | |
307 | 479 | | |
308 | 480 | | |
309 | 481 | | |
| |||
313 | 485 | | |
314 | 486 | | |
315 | 487 | | |
316 | | - | |
| 488 | + | |
317 | 489 | | |
318 | | - | |
| 490 | + | |
319 | 491 | | |
320 | 492 | | |
321 | 493 | | |
| |||
326 | 498 | | |
327 | 499 | | |
328 | 500 | | |
329 | | - | |
| 501 | + | |
0 commit comments