ome-zarr-py icon indicating copy to clipboard operation
ome-zarr-py copied to clipboard

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

Open maweigert opened this issue 2 years ago • 1 comments

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())


maweigert avatar Feb 22 '23 10:02 maweigert

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

toloudis avatar Feb 27 '23 19:02 toloudis