-
Notifications
You must be signed in to change notification settings - Fork 1
Support standard raster image formats #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||||||||||
| import logging | ||||||||||||||
| import os | ||||||||||||||
| import shutil | ||||||||||||||
| import importlib | ||||||||||||||
| from pathlib import Path | ||||||||||||||
| from typing import Any, Callable, Dict, List, Optional, Set, Union | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -23,7 +24,7 @@ | |||||||||||||
|
|
||||||||||||||
| def optional_import(module_name): | ||||||||||||||
| try: | ||||||||||||||
| return __import__(module_name) | ||||||||||||||
| return importlib.import_module(module_name) | ||||||||||||||
| except ImportError: | ||||||||||||||
| return None | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -44,6 +45,7 @@ def optional_import(module_name): | |||||||||||||
| cupy = get_cupy() | ||||||||||||||
| tf = get_tf() | ||||||||||||||
| tifffile = optional_import("tifffile") | ||||||||||||||
| imageio = optional_import("imageio.v3") | ||||||||||||||
|
|
||||||||||||||
| # Optional arraybridge integration for memory conversion | ||||||||||||||
| try: | ||||||||||||||
|
|
@@ -99,6 +101,7 @@ def _register_formats(self): | |||||||||||||
|
|
||||||||||||||
| # Complex formats - use custom handlers | ||||||||||||||
| (FileFormat.TIFF, tifffile, self._tiff_writer, self._tiff_reader), | ||||||||||||||
| (FileFormat.RASTER_IMAGE, imageio, self._image_writer, self._image_reader), | ||||||||||||||
| (FileFormat.TEXT, True, self._text_writer, self._text_reader), | ||||||||||||||
| (FileFormat.JSON, True, self._json_writer, self._json_reader), | ||||||||||||||
| (FileFormat.CSV, True, self._csv_writer, self._csv_reader), | ||||||||||||||
|
|
@@ -164,6 +167,14 @@ def _tiff_reader(self, path): | |||||||||||||
| else: | ||||||||||||||
| return tifffile.imread(str(path)) | ||||||||||||||
|
|
||||||||||||||
| def _image_writer(self, path, data, **kwargs): | ||||||||||||||
| """Write standard raster images using imageio.""" | ||||||||||||||
| imageio.imwrite(path, np.asarray(data)) | ||||||||||||||
|
|
||||||||||||||
| def _image_reader(self, path): | ||||||||||||||
| """Read standard raster images using imageio.""" | ||||||||||||||
| return imageio.imread(path) | ||||||||||||||
|
Comment on lines
+174
to
+176
|
||||||||||||||
| def _image_reader(self, path): | |
| """Read standard raster images using imageio.""" | |
| return imageio.imread(path) | |
| def _image_reader(self, path, **kwargs): | |
| """Read standard raster images using imageio.""" | |
| return imageio.imread(path, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raster image support is introduced here, but the test suite doesn’t cover saving/loading any of the new extensions (e.g., .png/.jpg/.bmp). Please add pytest coverage that round-trips a small array through at least one raster format and asserts the extension is registered/usable (and ideally verifies case-insensitive extension handling, e.g., '.PNG').