Page 1 of 1

Exporting images

PostPosted: Sat Jul 13, 2013 4:40 pm
by webvalley
Hello guys,
we are trying to create a python script (to run into omero) which will upload an image to a remote server via post.
The problem is that we can not figure out how to get either a PIL image or just raw binary data from an omero image.
This is the code we wrote so far:
Code: Select all
from omero.gateway import BlitzGateway
import omero.util.script_utils as scriptUtil
from omero.rtypes import *
import omero.scripts as scripts
import requests

try:
    from PIL import Image
except ImportError:
    import Image

if __name__ == "__main__":
    dataTypes = [rstring('Image')]
    client = scripts.client('TestUpload', """Testing the upload of an image to a remote server""",
                            scripts.String("Data_Type", optional=False, grouping="1",
                                           description="Choose source of images (only Image supported)",
                                           values=dataTypes, default="Image"),
                            scripts.List("IDs", optional=False, grouping="2",
                                         description="List of Image IDs to change annotations for.").ofType(rlong(0)),
                            version='0.1',
                            authors=['The WebValley Team', ""],
                            institutions=['WebValley'],
                            contact='webvalley@fbk.eu')

    try:
        # process the list of args above.
        scriptParams = {}
        for key in client.getInputKeys():
            if client.getInput(key):
                scriptParams[key] = client.getInput(key, unwrap=True)

        conn = BlitzGateway(client_obj=client)
        # updateService = conn.getUpdateService()

        images, logMessage = scriptUtil.getObjects(conn, scriptParams)

        for image in images:
            payload = {'file': image._obj}
            r = requests.post("http://192.168.205.10/post.php", files=payload)

    finally:
        client.closeSession()

Thank you very much for your help,
The WebValley Team

Re: Exporting images

PostPosted: Mon Jul 15, 2013 10:34 am
by atarkowska
Hi,

You have two options to do it. Either you can render thumbnail or image. Please find an examples how to do it in our training materials.

More details about BlitzGateway interface is available in the documentation.

I hope it will be helpful.

Ola

Re: Exporting images

PostPosted: Thu Jul 18, 2013 10:17 pm
by wmoore
You could also look at the https://github.com/ome/scripts/blob/mas ... _Export.py script, which ships with OMERO and uses PIL images to save images to disk. This will probably have most of the code you need.