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

Support for labels in reader #1

Open
nathandecaux opened this issue Jun 20, 2023 · 1 comment
Open

Support for labels in reader #1

nathandecaux opened this issue Jun 20, 2023 · 1 comment

Comments

@nathandecaux
Copy link

Hello,

Thanks for your work ! I've planned to used your plugin in my project in place on my own nifti reader/writer functions, however I'm missing a simple feature : loading layers as image or labels according to the nifti dtype.
There's no dev branch so I can't push it myself, but here's a sample of code that should do the trick :

def load_nifti(filename):
    image_data = sitk.ReadImage(filename)
    image = sitk.GetArrayFromImage(image_data)
    dtype = 'labels' if image.dtype in [np.uint8,np.uint16] else 'image'
    [...]
    return {"image": image, "affine": affine, "scale": scale, "dtype": dtype, "metadata": {"metadata": metadata, "origin": origin, "direction": direction, "spacing": spacing}}

and :

def reader_function(path):
    [...]
    layer_data = [(image_data["image"], {"affine": image_data["affine"], "metadata": image_data["metadata"]}, image_data["dtype"]) for image_data in image_data_list]
    return layer_data
@Karol-G
Copy link
Collaborator

Karol-G commented Jun 22, 2023

Hey @nathandecaux,

Thank you for this proposition. However, many Nifti images (not segmentations) are also of dtype uint8 or uint16. Always loading Nifti files of these datatypes as labels will cause issues for this scenario. Nifti has sadly no internal flag for this case so the only solution is to load segmentations as images and convert them in Napari to a labels layer.

Best,
Karol

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