Page 1 of 1

createImageFromNumpySeq() usage?

PostPosted: Fri Apr 20, 2018 12:02 am
by claybreshears
With some other scripts, I've read in a .svs image, converted to a numpy array and broke it up into smaller pieces (tiles), ran some things over each of the tiles, then stitched it back together. Now, before I try pulling the image from OMERO, I wanted to see about putting the modified image into OMERO from the numpy array.

The shape of my array is (46129, 61752, 3). This is a single layer from the original .svs and each pixel represented with 3 values (RGB) where each value is dtype=uint8. Thus, I have one plane (image layer). I have no Z stack and no Time sequence. I'm assuming that the sizes for those parameters should each be '1' and the Color size is '3'. My script bits, cribbed from the documentation example:

Code: Select all
planes = [reconstitutedArrayFromTiles]
sizeZ = sizeT = 1
sizeC = 3
desc = "Image created from reading numpy array off disk"
i = conn.createImageFromNumpySeq(
    plane_gen(), "numpy image", sizeZ, sizeC, sizeT, description=desc,
    dataset=None)


This keeps giving me the following error:
Code: Select all
ERROR:omero.gateway:Failed to setPlane() on rawPixelsStore while creating Image
Traceback (most recent call last):
  File "/home/omero/OMERO.server/lib/python/omero/gateway/__init__.py", line 3764, in createImageFromNumpySeq
    image, dtype = createImage(plane, channelList)
  File "/home/omero/OMERO.server/lib/python/omero/gateway/__init__.py", line 3684, in createImage
    sizeY, sizeX = firstPlane.shape
ValueError: too many values to unpack
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-102-c91df066e6d0> in <module>()
      3 i = conn.createImageFromNumpySeq(
      4     p_gen(), "numpy image", sizeZ, sizeC, sizeT, description=desc,
----> 5     dataset=None)
      6 print 'Created new Image:%s Name:"%s"' % (i.getId(), i.getName())

/home/omero/OMERO.server/lib/python/omero/gateway/__init__.pyc in createImageFromNumpySeq(self, zctPlanes, imageName, sizeZ, sizeC, sizeT, description, dataset, sourceImageId, channelList)
   3791                 exc = e
   3792         if exc is not None:
-> 3793             raise exc
   3794
   3795         # simply completing the generator - to avoid a GeneratorExit error.

ValueError: too many values to unpack


The error makes me think that there is more data in the array than the function was expecting. Have I got my parameters/dimensions correct? Is the organization of the array correct? Should I have more planes? Anything else that I've obviously messed up?

Re: createImageFromNumpySeq() usage?

PostPosted: Mon Apr 23, 2018 8:56 am
by wmoore
Hi,

I'm not sure from your example exactly what
Code: Select all
plane_gen()
is returning, but it should return a generator of 2D numpy planes. The first one is used to get the sizeY and sizeX for the new image via
Code: Select all
firstPlane.shape
but it seems that the first item that the generator returns is not a numpy 2D plane, since this returns more than 2 values.

However, in your case, with an image of that size you will not be able to create an image from a series individual planes but will have to use tiles instead.

You can find an example of this in the Images_From_ROIs.py script that crops a large image to create another large (tiled) image. See create_image_from_tiles() at https://github.com/ome/scripts/blob/dev ... OIs.py#L47

You will need to take and modify most of the code under create_image_from_tiles(). To create your own tile_gen() generator you could place the nested for loops for t, c, z, y, x under a tile_gen() and yield an appropriate tile.

Code: Select all
def tile_gen()
    // for loops....
        // get tile (2D numpy array) for t, c, z, y, x
        yield tile


Hope that helps,

Will.