Skip to content

to_multiscale fails with scale_factors not power of 2 #264

@lorenzocerrone

Description

@lorenzocerrone

I was experimenting with non-conventional scaling factor and I noticed that when the scaling factor is not a power of 2, the zarr array shapes are not correct. The ngff metadata is correct.

To reproduce:

import ngff_zarr as nz
import numpy as np

# Generate pixel data (e.g. from a microscope, simulation, etc.)
data = np.random.randint(0, 256, size=(120, 120), dtype=np.uint8)
image = nz.to_ngff_image(data, scale={'y': 1.0, 'x': 1.0})

multiscales = nz.to_multiscales(image, scale_factors=[2, 3, 4])
nz.to_ngff_zarr('example.ome.zarr', multiscales)
image = nz.from_ngff_zarr('example.ome.zarr')
# original ok
assert image.images[0].data.shape == (120, 120)
# factor 2 ok
assert image.images[1].data.shape == (60, 60)
# factor 4 ok 
assert image.images[3].data.shape == (30, 30)
# factor 3 is wrong ==> should be (40, 40) but is (60, 60)
assert image.images[2].data.shape == (40, 40), image.images[2].data.shape

Version ngff_zarr==0.20.1

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions