Skip to content
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

add doc for ome zarr writer #551

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in P
- Files supported by [Bio-Formats](https://docs.openmicroscopy.org/bio-formats/latest/supported-formats.html) -- (`pip install aicsimageio bioformats_jar`) (Note: requires `java` and `maven`, see below for details.)
- Supports writing metadata and imaging data for:
- `OME-TIFF`
- `OME-ZARR`
- `PNG`, `GIF`, [etc.](https://github.com/imageio/imageio) -- (`pip install aicsimageio[base-imageio]`)
- Supports reading and writing to
[fsspec](https://github.com/intake/filesystem_spec) supported file systems
Expand Down Expand Up @@ -304,7 +305,7 @@ as an OME-TIFF, the writer class can also be used to customize as needed.

```python
import numpy as np
from aicsimageio.writers import OmeTiffWriter
from aicsimageio.writers.ome_tiff_writer import OmeTiffWriter

image = np.random.rand(10, 3, 1024, 2048)
OmeTiffWriter.save(image, "file.ome.tif", dim_order="ZCYX")
Expand All @@ -314,6 +315,35 @@ See
[OmeTiffWriter documentation](./aicsimageio.writers.html#aicsimageio.writers.ome_tiff_writer.OmeTiffWriter.save)
for more details.

### Saving to OME-ZARR
In-built writer for OME-ZARR output, effectively towards large image data

```python
from aicsimageio import AICSImage, types
from aicsimageio.writers.ome_zarr_writer import OmeZarrWriter

image = np.random.rand(3, 10, 1024, 2048)
channel_colors = ["FFFFFF","00FFFF","0000FF"]
int_color = [int(c, 16) for c in channel_colors]

writer = OmeZarrWriter("./test.ome.zarr")

writer.write_image(
image,
image_name="Image:0",
physical_pixel_sizes=types.PhysicalPixelSizes(X=0.5, Y=0.5, Z=1.0), # in um
channel_names=["C00","C01","C02"],
channel_colors=int_color,
scale_num_levels=3,
scale_factor=2.0,
dimension_order="CZYX"
)
```

See
[OmeZarrWriter documentation](./aicsimageio.writers.html#aicsimageio.writers.ome_zarr_writer.OmeZarrWriter.save)
for more details.

#### Other Writers

In most cases, `AICSImage.save` is usually a good default but there are other image
Expand Down
40 changes: 40 additions & 0 deletions aicsimageio/writers/ome_zarr_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,46 @@ def write_image(
... writer = OmeZarrWriter("/path/to/file.ome.zarr")
... writer.write_image(image0, "Image:0", ["C00","C01","C02"])
... writer.write_image(image1, "Image:1", ["C10","C11","C12"])

Write multi-scale image to OME-Zarr
>>> image = numpy.ndarray([3, 10, 1024, 2048])
... writer = OmeZarrWriter("/path/to/file.ome.zarr")
... writer.write_image(
... data,
... image_name="Image:0",
... channel_names=["C00","C01","C02"],
... scale_num_levels=3,
... scale_factor=2.0,
... dimension_order="CZYX"
... )

Write image channel color to OME-Zarr
>>> image = numpy.ndarray([3, 10, 1024, 2048])
... channel_colors = ["FFFFFF","00FFFF","0000FF"]
... int_color = [int(c, 16) for c in channel_colors]
... writer = OmeZarrWriter("/path/to/file.ome.zarr")
... writer.write_image(
... data,
... image_name="Image:0",
... channel_names=["C00","C01","C02"],
... channel_colors=int_color,
... dimension_order="CZYX"
... )

Write pixel size to OME-Zarr
>>> from aicsimageio import AICSImage, types
... image = numpy.ndarray([3, 10, 1024, 2048])
... channel_colors = ["FFFFFF","00FFFF","0000FF"]
... int_color = [int(c, 16) for c in channel_colors]
... writer = OmeZarrWriter("/path/to/file.ome.zarr")
... writer.write_image(
... data,
... image_name="Image:0",
... physical_pixel_sizes=types.PhysicalPixelSizes(X=0.5, Y=0.5, Z=1.0)
... channel_names=["C00","C01","C02"],
... channel_colors=int_color,
... dimension_order="CZYX"
... )
"""
ndims = len(image_data.shape)
if ndims < 2 or ndims > 5:
Expand Down