Skip to content

Add crop_zarr.py#2

Open
will-moore wants to merge 4 commits intomainfrom
crop_zarr_rfc5
Open

Add crop_zarr.py#2
will-moore wants to merge 4 commits intomainfrom
crop_zarr_rfc5

Conversation

@will-moore
Copy link
Copy Markdown
Owner

@will-moore will-moore commented Oct 14, 2025

Work in progress...

A script to create sample OME-Zarr RFC-5 images.

NB: this script requires the version of ome-zarr-py from ome/ome-zarr-py#492

This script takes a ~large OME-Zarr v0.5 or (v0.4) image and crops a region
from it, optionally rotating the region in the XY plane. The cropped region is
then saved as a new OME-Zarr v0.6 dataset, with appropriate metadata including
coordinate transformations to place the cropped region in the same physical
space as the original image.

This should work with 2D, 3D, 4D or 5D OME-Zarrs.

NB: requires napari to be installed as it uses napari Affine transform to generate affine matrices.

Usage:

$ python crop_zarr.py <path> <xywh> <rotation>

The following will create 2 tiles and the original 'full' image,
all under a new top-level zarr group:

$ python crop_zarr.py 9036345.ome.zarr/ 300,300,300,300 20
$ python crop_zarr.py 9036345.ome.zarr/ 200,200,200,200 30
$ python crop_zarr.py 9036345.ome.zarr/ full 0

EDIT: 3rd November
With ome-zarr-py on 37a7526 and this branch on e5c82da, the sample at https://uk1s3.embassy.ebi.ac.uk/idr/zarr/test-data/v0.6dev2/idr0050/4995115_tiles.zarr (see screenshot at will-moore/napari-ome-zarr#2) was created with:

$ python /Users/wmoore/Desktop/python-scripts/zarr_scripts/ome-zarr-py/crop_zarr.py 4995115.ome.zarr/ full 0
$ python /Users/wmoore/Desktop/python-scripts/zarr_scripts/ome-zarr-py/crop_zarr.py 4995115.ome.zarr/ 400,100,400,400 10 --labels
$ python /Users/wmoore/Desktop/python-scripts/zarr_scripts/ome-zarr-py/crop_zarr.py 4995115.ome.zarr/ 700,700,400,400 45 --labels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant