OME-Zarr Creation¶
This is a minimal example of how to create an OME-Zarr image using ngio.
This example is just a simple demonstration but for more complex conversion tasks please refer to the converter tooling library ome-zarr-converters-tools.
Let's start by converting a sample image from skimage to OME-Zarr format.
In [1]:
Copied!
import skimage
from matplotlib import pyplot as plt
plt.imshow(skimage.data.human_mitosis(), cmap="gray")
plt.axis("off")
plt.show()
import skimage
from matplotlib import pyplot as plt
plt.imshow(skimage.data.human_mitosis(), cmap="gray")
plt.axis("off")
plt.show()
/opt/hostedtoolcache/Python/3.13.11/x64/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm Downloading file 'data/mitosis.tif' from 'https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/AS_09125_050116030001_D03f00d0.tif' to '/home/runner/.cache/scikit-image/0.26.0'.
In [2]:
Copied!
from ngio import create_ome_zarr_from_array
ome_zarr = create_ome_zarr_from_array(
store="./data/human_mitosis.zarr",
array=skimage.data.human_mitosis(),
pixelsize=0.1, # Just a guess
)
ome_zarr
from ngio import create_ome_zarr_from_array
ome_zarr = create_ome_zarr_from_array(
store="./data/human_mitosis.zarr",
array=skimage.data.human_mitosis(),
pixelsize=0.1, # Just a guess
)
ome_zarr
Out[2]:
OmeZarrContainer(levels=5)
Adding a ROI table to an OME-Zarr image¶
Often, is useful to add ROIs to OME-Zarr images to be able to retrieve them later.
This can be done using the ngio library as follows.
In [3]:
Copied!
# create a roi for the whole image
roi_table = ome_zarr.build_image_roi_table(name="image_roi")
ome_zarr.add_table("image_roi_table", roi_table)
# create a roi for the whole image
roi_table = ome_zarr.build_image_roi_table(name="image_roi")
ome_zarr.add_table("image_roi_table", roi_table)
/opt/hostedtoolcache/Python/3.13.11/x64/lib/python3.13/site-packages/anndata/_io/zarr.py:44: UserWarning: Writing zarr v2 data will no longer be the default in the next minor release. v3 data will be written by default. If you are explicitly setting this configuration, consider migrating to the zarr v3 file format. f = open_write_group(store)