OMERO.py: How to get tiles at different zoom level (pyramidal image)?

Hello,

I just discovered omero.py and it looks very nice! I wonder if it possible get tiles at other zoom level than the native resolution?

I am following this guide: https://docs.openmicroscopy.org/omero/5.6.0/developers/Python.html

For instance, this works fine:

from omero.gateway import BlitzGateway

conn = BlitzGateway("username", "password", port=4064, host="localhost")
conn.connect()

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

pixels = image.getPrimaryPixels()
tile = (0, 0, 256, 256)
im = pixels.getTile(0, 0, 0, tile)

Now I would like to the the same at different zoom level of the pyramid. The target image is an ome.tiff file, tiled and pyramidal. Is it possible?

Kind regards

I’m afraid that’s not supported by the PixelsWrapper.getTile().
You’ll need to do a bit more work to use the underlying rawPixelsStore.

Hopefully this will work:

import numpy as np
from omero.gateway import BlitzGateway
from omero.model import enums as omero_enums

conn = BlitzGateway('user', 'password', port=4064, host='localhost')
conn.connect()

PIXEL_TYPES = {
    omero_enums.PixelsTypeint8: np.int8,
    omero_enums.PixelsTypeuint8: np.uint8,
    omero_enums.PixelsTypeint16: np.int16,
    omero_enums.PixelsTypeuint16: np.uint16,
    omero_enums.PixelsTypeint32: np.int32,
    omero_enums.PixelsTypeuint32: np.uint32,
    omero_enums.PixelsTypefloat: np.float32,
    omero_enums.PixelsTypedouble: np.float64,
}

IMAGE_ID = 2566
image = conn.getObject("image", IMAGE_ID)
print('image', image.name)

pixels = image.getPrimaryPixels()
dtype = PIXEL_TYPES.get(pixels.getPixelsType().value, None)

pix = image._conn.c.sf.createRawPixelsStore()
pid = image.getPixelsId()
level = 0
z, c, t, x, y = (0, 0, 0, 0, 0)

try:
    pix.setPixelsId(pid, False)

    # Get info on number of levels and sizes
    print([(r.sizeX, r.sizeY) for r in pix.getResolutionDescriptions()])

    pix.setResolutionLevel(2)
    print(pix.getTileSize())
    w, h = pix.getTileSize()
    tile = pix.getTile(z, c, t, x, y, w, h)
finally:
    pix.close()

tile = np.frombuffer(tile, dtype=dtype)
tile = tile.reshape((h, w))

print(tile.shape)

Regards,
Will

1 Like

Excellent, thanks a lot!

1 Like