Upload ROIs to OMERO

Hi @OMETeam,

I have a Fiji python script to open all images in a dataset from OMERO, do processing, find objects and make measurements in those objects. Now I’d like to upload back the ROIs of the objects in OMERO, linked to the image, is that possible ?

I checked this documentation but can’t find anything about sending back to OMERO. Any help would be welcome thanks !

1 Like

Hi @lguerard

By Fiji python script, I assume you are using a Jython script.
We have few examples in groovy in omero-guide-fiji and in Jython in training-scripts. I am in the process of migrating the Jython scripts to the omero-guide-fiji repository so that user can evaluate them in mybinder.org.

We have opted to use groovy since it has proven to be easier to explain to the user.
In both cases you will need the omero.insight imageJ plugin.

Cheers

Jmarie

1 Like

Hi @lguerard, for a pure python example, I wrote that function, if that helps:

Best,

Guillaume

1 Like

Hi @glyg, thanks a lot for the link, I’ll have a look but I was indeed talking about Jython since I’m still using the Fiji GUI. :slight_smile:

Hi @j.burel, thanks a lot for the links ! I couldn’t find any function to upload ROIs back to OMERO in the Jython training scripts but could find it in Groovy so I’ll try and adapt it. I’ll let you know how it goes ! :slight_smile:

Good morning

In idr0021.jy, ImageJ ROI are converted into OMERO ROI and saved back to the server.
If you have other types of ROIs, this is an example on how to save trackmate tracks into OMERO

I hope it helps

Cheers

Jmarie

1 Like

Good morning !

Thanks a lot for both links, this is super helpful ! :slight_smile:

Hi @j.burel,

Just another question on the subject. Running multiple times the script on an OMERO dataset will add ROIs every time. Is there any way to delete the existing ROIs when running a script ?

Thanks a lot !

Hi @Iguerard

Below is a code snippet in Jython for your script deleting the rois linked to an image

svc = gateway.getFacility(ROIFacility)
dm = gateway.getFacility(DataManagerFacility)
roiresults = svc.loadROIs(ctx, image_id)
r = roiresults.iterator().next()
if r is None:
   print("ro rois")
else:
   rois = r.getROIs()
   to_delete = []
   for roi in r.getROIs():
       to_delete.append(roi.asIObject())
  dm.delete(ctx, to_delete).loop(10, 500)  # return a callback

I will add that to one of our example since it is a useful example to have
I will also migrate the Jython scripts for Fiji to the omero-guide-fiji so everything is in one location

If you are using groovy, the same logic will apply

Jmarie

1 Like

Hi,

Thanks a lot for the very fast and precise answer, this is exactly what I was looking for :slight_smile:

Best,
Laurent

Hi @j.burel,

Sorry for the double post, but I just tried running your script and somehow it seems that it only deletes them 4 by 4. Like I’m running it once and I have 690 ROIs in OMERO, then 686 etc…

Here is this part of the script so that you can see I didn’t change anything :

for index_image,imageId in enumerate(imageIds):

    roiresults = svc.loadROIs(ctx, long(imageId))
    r = roiresults.iterator().next()
    if r is None:
    	print("no rois")
    else:
	    rois = r.getROIs()
	    print(len(rois))
	    to_delete = []
	    for roi in rois:
	        to_delete.append(roi.asIObject())

	   dm.delete(ctx, to_delete).loop(10, 500)

    openImagePlus(HOST, USERNAME, PASSWORD, groupId, imageId)
    IJ.run("Hide Overlay", "");
    
    sys.exit(0)

Could try to delete one-by-one i.e.

for roi in rois:
    dm.delete(ctx, [roi.asIObject()]).loop(10, 500)
2 Likes

Thanks, somehow this seems to work ! :slight_smile: