Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Support for loading images as a stack #61

Description

@MosGeo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions