|
1 | 1 | # ViData: Vision Data Management, Processing and Analysis |
2 | 2 |
|
3 | | -> A unified Python toolkit for managing, processing, and analyzing vision datasets — from raw data to task specific analytics. |
| 3 | +> A unified Python toolkit for managing, processing, and analyzing vision datasets, from raw data to task specific analytics. |
4 | 4 | > |
5 | | -> streamlines the entire data pipeline for computer vision and medical imaging: |
| 5 | +> Streamlines the entire data pipeline for computer vision and medical imaging: |
6 | 6 | > |
7 | 7 | > - Load and save 2D/3D data across common formats with a consistent API. |
8 | 8 | > - Organize datasets using flexible file managers and YAML-based configs. |
@@ -52,6 +52,7 @@ pip install napari-data-inspection |
52 | 52 | - Use `load_xxx` / `save_xxx` for all supported formats. |
53 | 53 | - **Images/arrays:** PNG/JPG/TIFF (`imageio`, `tifffile`), NIfTI/NRRD/MHA (`sitk`, `nibabel`), Blosc2, NumPy (`.npy`, `.npz`). |
54 | 54 | - **Configs/metadata:** JSON, YAML, Pickle, TXT. |
| 55 | +- **Extendable** by custom _load_ and _save_ functions. |
55 | 56 | - Functions always follow the same pattern: |
56 | 57 |
|
57 | 58 | ```python |
@@ -153,6 +154,52 @@ obj = load_txt("config.txt") |
153 | 154 | save_txt(obj, "out.txt") |
154 | 155 | ``` |
155 | 156 |
|
| 157 | +### Custom Load and Save Functions |
| 158 | + |
| 159 | +- Register a reader / writer with a decorator. |
| 160 | +- Reader must return (numpy_array, metadata_dict). |
| 161 | +- Writer must return list\[str\] of the file(s) it wrote. |
| 162 | +- Registration happens at import time—make sure this module is imported (e.g., from your package’s __init__.py). |
| 163 | +- See [here](https://github.com/MIC-DKFZ/ViData/blob/main/src/vidata/io/image_io.py) for an example. |
| 164 | + |
| 165 | +```py |
| 166 | +# custom_io_template.py — fill in the TODOs and import this module somewhere at startup. |
| 167 | +import numpy as np |
| 168 | +from typing import Tuple, Dict, List |
| 169 | + |
| 170 | +# TODO: import your backend library (e.g., imageio, tifffile, nibabel, SimpleITK, ...) |
| 171 | +# import imageio.v3 as iio |
| 172 | + |
| 173 | +from vidata.registry import register_loader, register_writer |
| 174 | + |
| 175 | +# --------------------------- READER ------------------------------------------ |
| 176 | +# Replace file extension and backend name to your custom function |
| 177 | +@register_loader("image", ".png", ".jpg", ".jpeg", ".bmp", backend="imageio") # To Register Image Loading |
| 178 | +@register_loader("mask", ".png", ".bmp", backend="imageio") # To Register Label Loading |
| 179 | +def load_custom(file: str) -> tuple[np.ndarray, dict]: |
| 180 | + """ |
| 181 | + Load a file and return (data, metadata). |
| 182 | + metadata can be empty or include keys like: spacing, origin, direction, shear, dtype, etc. |
| 183 | + """ |
| 184 | + # data = iio.imread(file) # example for imageio |
| 185 | + data = ... # TODO: replace |
| 186 | + meta = {} # TODO: replace |
| 187 | + return data, meta |
| 188 | + # return meta # for metadata files like json or yaml |
| 189 | + |
| 190 | +# --------------------------- WRITER ------------------------------------------ |
| 191 | +# Replace file extension and backend name to your custom function |
| 192 | +@register_writer("image", ".png", ".jpg", ".jpeg", ".bmp", backend="imageio") # To Register Image Writer |
| 193 | +@register_writer("mask", ".png", ".bmp", backend="imageio") # To Register Label Writer |
| 194 | +def save_custom(data: np.ndarray, file: str) -> list[str]: |
| 195 | + """ |
| 196 | + Save array to `file`. Return all created paths (include sidecars if any). |
| 197 | + """ |
| 198 | + # TODO: write using your backend |
| 199 | + # iio.imwrite(file, data) |
| 200 | + return [file] |
| 201 | +``` |
| 202 | + |
156 | 203 | </details> |
157 | 204 |
|
158 | 205 | # Loaders/Writers |
@@ -579,8 +626,7 @@ This repository is developed and maintained by the Applied Computer Vision Lab ( |
579 | 626 | of [Helmholtz Imaging](https://www.helmholtz-imaging.de/) and the |
580 | 627 | [Division of Medical Image Computing](https://www.dkfz.de/en/medical-image-computing) at DKFZ. |
581 | 628 |
|
582 | | -This [napari] plugin was generated with [copier] using the [napari-plugin-template]. |
| 629 | +This repository was generated with [copier] using the [napari-plugin-template]. |
583 | 630 |
|
584 | 631 | [copier]: https://copier.readthedocs.io/en/stable/ |
585 | | -[napari]: https://github.com/napari/napari |
586 | 632 | [napari-plugin-template]: https://github.com/napari/napari-plugin-template |
0 commit comments