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 loading images as a stack #61

Open
MosGeo opened this issue Aug 22, 2022 · 0 comments
Open

Support for loading images as a stack #61

MosGeo opened this issue Aug 22, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@MosGeo
Copy link

MosGeo commented Aug 22, 2022

Use Case

I thought to open this issue to discuss. napari-aicsimageio does not support open folder right now. It would be good if it supported it.

Solution

Here is a possible implementation. Some notes:

  1. I am using AICSImage. As I understand it, napari-aicsimageio now uses the raw reader data.
  2. I am using the dask interface.
  3. I am saving the filenames in the meta data. This is useful for my plugins.
  4. The metadata aicsimage is still aicsimage and not aicsimages. Again, I like standardization. But in this case, it is returning a list of images.
def load_image_stacks_to_viewer(viewer:napari.Viewer, filenames:list[Path])->None:
    """Loads image stack"""
    # Stopping condition
    if len(filenames)==0:
        return None

    # Load images
    images:list[AICSImage] = []
    for filename in filenames:
        image = AICSImage(filename)
        images.append(image)

    # Stopping condition - Check sizes
    reference_image_size = images[0].shape
    is_all_same_size = all([np.all(image.shape==reference_image_size) for image in images])
    if not is_all_same_size:
        show_message_box(viewer.window,
                         message="Stack cannot be compiled. All images need to be of the same size.",
                         title='Load Images as Stack')
        return

    # Stack images
    data = [image.dask_data for image in images]
    image_stack = da.concatenate(data, axis=2)
    image_layer = viewer.add_image(image_stack, name=filenames[0].stem)
    image_layer.metadata['aicsimage'] = images
    image_layer.metadata['filename'] = filenames
    viewer.reset_view()

Alternatives

  1. Load images seperatly.
  2. Combine them to stack
@psobolewskiPhD psobolewskiPhD added the enhancement New feature or request label Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants