Napari loading images from OMERO


I just heard about your nice napari viewer and since we are working on python3 support for OMERO (Call Omero API from python3?) the timing is great.

Here’s some sample code to view a Z-stack multi-channel image from OMERO in napari.

import napari
from vispy.color import Colormap
import numpy
from omero.gateway import BlitzGateway
conn = BlitzGateway('username', 'password', port=4064, host="omero.server")

IMAGE_ID = 4418
image = conn.getObject("Image", IMAGE_ID)

def get_z_stack(img, c=0, t=0):
    zct_list = [(z, c, t) for z in range(img.getSizeZ())]
    pixels = image.getPrimaryPixels()
    return numpy.array(list(pixels.getPlanes(zct_list)))

with napari.gui_qt():
    viewer = napari.Viewer()

    for c, channel in enumerate(image.getChannels()):
        print('loading channel %s' % c)
        data = get_z_stack(image, c=c)
        # use current rendering settings from OMERO
        color = channel.getColor().getRGB()
        color = [r/256 for r in color]
        cmap = Colormap([[0, 0, 0], color])
        # Z-scale for 3D viewing
        size_x = image.getPixelSizeX()
        size_z = image.getPixelSizeZ()
        z_scale = size_z / size_x
        viewer.add_image(data, blending='additive',
                         colormap=('from_omero', cmap),
                         scale=[1, z_scale, 1, 1],

    print('closing conn...')




Here’s the current screenshot:


This is awesome. Exactly what I have been looking for!
Might be a good solution for this as well
(5D volume viewing in Python)

1 Like

This is really cool!

EDIT: I updated the code sample above to include channel label, color and Z-scale metadata from OMERO.

1 Like

@will-moore - I wanted point you towards this recent “meta-issue” around improving napari’s support for remote data + remote compute. You can see how we’re planning to lean into the dask ecosystem, though some of those improvements will help with any lazy loading approach. Curious what you make of those plans from your OMERO perspective or if there is more we could do to improve performance / ease of your use case.

Feel free to weigh in here or on that issue directly, thanks!! :slight_smile: