Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_multiscale with Methods.ITK_LABEL_GAUSSIAN throws error for certain data types #79

Open
ahnsws opened this issue Aug 11, 2023 · 1 comment

Comments

@ahnsws
Copy link

ahnsws commented Aug 11, 2023

Hello, we would like to use to_multiscale to generate downscaled pyramids of label arrays. Unfortunately, it looks like the ITK_LABEL_GAUSSIAN method only works for certain data types. Please see the snippet below:

import dask.array as da
import numpy as np
from multiscale_spatial_image import to_multiscale, Methods
from spatial_image import to_spatial_image, SpatialImage


def try_multiscale_label():
    """
    types:
    - int8   failed -> itk.support.extras.TemplateTypeError: itk.Image is not wrapped for input type `itk.SC, int`.
    - int16  worked, but max val not big enough
    - int32  failed -> itk.support.extras.TemplateTypeError: itk.BinShrinkImageFilter is not wrapped for input type `None`.
    - int64  failed -> itk.support.extras.TemplateTypeError: itk.Image is not wrapped for input type `itk.SL, int`.

    - uint8  worked, but max val not big enough
    - uint16 worked, but max val not big enough
    - uint32 failed -> itk.support.extras.TemplateTypeError: itk.BinShrinkImageFilter is not wrapped for input type `None`.
    - uint64 failed -> itk.support.extras.TemplateTypeError: itk.BinShrinkImageFilter is not wrapped for input type `None`.
    """
    labels_arr: da.Array = da.zeros(shape=(100, 100), dtype=np.uint64)
    labels_arr[:50, :50] = 1

    labels: SpatialImage = to_spatial_image(labels_arr, dims=("y", "x"))
    to_multiscale(
        labels,
        scale_factors=[dict(y=2, x=2)],
        method=Methods.ITK_LABEL_GAUSSIAN,
    )


if __name__ == "__main__":
    try_multiscale_label()

For int8, int32, int64, uint32, and uint64, there is an error thrown, and it seems like this will take me into the weeds a bit. If you have any suggestions on how to approach fixing this I am all ears.

Edit: the dependencies for the above snippet are:

python==3.10.12
multiscale-spatial-image==0.11.2
dask==2023.8.0
numpy==1.25.2
zarr==2.16.0
itk==5.3.0

Thank you,
Seb

@dzenanz
Copy link
Collaborator

dzenanz commented Aug 11, 2023

Considering wrapping specification, enabling ITK_WRAP_signed_long during package creation should fix your problem. Read more about ITKPythonPackage, and its docs.

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

No branches or pull requests

2 participants