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!


1 Like

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.


Dear OME Team,

I need to load sets of images in a dataset with ( ****.czi file format ) in jupyter Notebook. I tried this function:

def load_image(conn, image_id):
return conn.getObject(‘Image’, image_id)

to read *****.czi files from OMERO, but it did not work.
It resulted in Nonetype output. Is there any alternative to read these format of images?

Thank you in advance.

It might be that your image is in a different group, or you don’t have permission to access it. You could try this before conn.getObject(), to query across all groups:


Hi Will,

Thank you for your point. It worked perfectly.

Hi Josh and Will,

I need to do a reverse search, basically I found missing links in ManagedRepository due to ln_s but someone didn’t lockdown those files, users moved, rename or delete them.

So I found all the missing links in ManagedRepository. So I need to do a search for the image ID.

Doing it on sql, I can find the originalFile ID from below

psql -h localhost -U omero -d omero -c “select, from originalfile as ofile where like ‘%2021_03_04__08_50__0004%’” -W
Password for user omero:
id | name
13408 | 2021_03_04__08_50__0004_2_pt1.czi
13411 | 2021_03_04__08_50__0004_2_pt2.czi
13414 | 2021_03_04__08_50__0004_Preview.czi
(3 rows)
But what should I join on the Image table? I was guessing that originalfile name = image name, obivoulsy I was wrong. Do I need to join more tables from reading the abve.
psql -h localhost -U omero -d omero -c “select, from originalfile as ofile join image as i on = where like ‘%2021_03_04__08_50__0004%’ limit 10” -W
Password for user omero:
id | name
(0 rows)

Or is there a much easier route to do the above?

Thanks in advance

Hi Ken,

you can take a look at Glossary of all OMERO Model Objects — OMERO 5.6.3 documentation for more details, but the basic path you need is:

image.fileset == == filesetEntry.fileset and filesetEntry.originalFile ==


1 Like

Thanks Josh. Most useful.

Got it working. In case others want to do the same. Here is the sql below:

$ psql -h localhost -U omero -d omero -c “select,,, ofile.path from image as i join fileset as fs on = i.fileset join filesetentry as fse on join originalfile as ofile on fse.originalfile = where like ‘%2021_03_04__08_50__0004%’ limit 10” -W


1 Like