Path to Images In OMERO

Hello everyone,

I have a Python script which needed to be uploaded into OMERO. I need to stitch images of a specific folder which have been already uploaded into OMERO server. How can I provide a Path for my Images in Python Script Code, that can be understandable for OMERO and be able to run it?

It would be greatly appreciated if you help me in this case.


Hi @Pegah,

Something like the following:

   # Setup
   image_id = SOMETHING_HERE
   client = MUST_BE_DEFINED

   import os
   from omero.rtypes import unwrap
   resources = client.sf.sharedResources()
   repos = resources.repositories()
   for desc in repos.descriptions:
       if == "ManagedRepository":
           managed_repo_dir = desc.path.val +

   params = omero.sys.ParametersI()
   rows = client.sf.getQueryService().projection("""
       SELECT DISTINCT, ofile.path
           || FROM Image AS i
       JOIN i.fileset AS f
       JOIN f.usedFiles AS fe
       JOIN fe.originalFile AS ofile
       WHERE = :id""", params, {"": "-1"})
   imported_file = os.path.join(managed_repo_dir, unwrap(rows[0][1]))

should give you the path to the first imported file for an image.

:warning: Heads up for anyone using this code: Since only a user who should have permissions to access the image should be allowed to run this code, it is safe as written. Be careful though to not introduce a backdoor into your /OMERO/ManagedRepository!


Hi Josh,

Thank you so much for your reply. I am still working on that. Meanwhile I have another question. I could run a script in OMERO. This script is able to read the original metadata of every desired image by asking for their ImageID. Now I want to save some how this original metadata to a form of for example csv file or xlsx file and save it in it’s related Dataset. is there any way to do that?

Thank you so much in advanced.

The Image acquisition metadata in OMERO is structured according to the OME model and is stored in lots of different tables in the database. So you have to know where to look for the specific metadata you’re interested in (there isn’t a single way to list “All Metadata”).

You might find useful the code that the webclient uses to load metadata for the right-hand “Acquisition” tab. For example, loading Channel metadata at omero-web/ at 6049673b5ee43cb01149456588c1e8ed3d0b7b8c · ome/omero-web · GitHub which uses channel_metadata from omero-web/ at 6049673b5ee43cb01149456588c1e8ed3d0b7b8c · ome/omero-web · GitHub.
Other Image metadata for Objectives etc is loaded at omero-web/ at 6049673b5ee43cb01149456588c1e8ed3d0b7b8c · ome/omero-web · GitHub

There is an example of how to create a csv file and create a file annotation on OMERO at omero-scripts/ at c0d1733c96b4ea2ab7007d51fb12f5922d81d9c4 · ome/omero-scripts · GitHub
Actually, this doesn’t use the built-in python csv library (csv — CSV File Reading and Writing — Python 3.9.2rc1 documentation) which would be an improvement.

Link it to a Dataset like this:

file_ann = conn.createFileAnnfromLocalFile(file_name, mimetype="text/csv")
dataset = conn.getObject("Dataset", dataset_id)

Let us know if you need help finding the metadata you want. And if you could share the code you’re working on, that would help us to help you.