ome / ome-zarr-py

Implementation of next-generation file format (NGFF) specifications for storing bioimaging data in the cloud.
https://pypi.org/project/ome-zarr
Other
150 stars 53 forks source link

Multiscale method in write_images ignored (e.g. nearest vs gaussian) #254

Open maweigert opened 1 year ago

maweigert commented 1 year ago

Hi,

It seems that writing an image pyramid always uses nearest downsampling even if a different method is provided (e.g. gaussian):

https://github.com/ome/ome-zarr-py/blob/1f47e59fcda1eb551b59e32ddb35dd676a6e8f91/ome_zarr/writer.py#L830

Changing this line to

mip = getattr(scaler, scaler.method)(image)

might already be enough.

Example:

import numpy as np
from ome_zarr.scale import Scaler
from ome_zarr.writer import write_image
import zarr
x = np.random.uniform(0,1,(100,100))

store = parse_url('foo1.zarr', mode="w").store
root = zarr.group(store=store)
write_image(image=x, group=root, axes="yx", storage_options=dict(overwrite=True), scaler=Scaler(method='nearest'))

store = parse_url('foo2.zarr', mode="w").store
root = zarr.group(store=store)
write_image(image=x, group=root, axes="yx", storage_options=dict(overwrite=True), scaler=Scaler(method='gaussian'))

print(np.abs(np.asarray(zarr.open('foo1.zarr/')[1])-np.asarray(zarr.open('foo2.zarr/')[1])).max())
toloudis commented 1 year ago

There is also the use of order=1 in this line (used in the case of dask arrays): https://github.com/ome/ome-zarr-py/blob/master/ome_zarr/scale.py#L153