IDR Python API for ROIs?

from idr import connection
conn = connection('', 'public', 'public')

# %matplotlib inline
imageId = 1229801
# Pixels and Channels will be loaded automatically as needed
image = conn.getObject("Image", imageId)
roi_service = conn.getRoiService()
result = roi_service.findByImage(imageId, None)

roi = result.rois[0]
roi_image = roi.getImage() # UnloadedEntityException: Object unloaded:object #0 (::omero::model::Image)
roi_shape = roi.getPrimaryShape()
roi_points = roi_shape.getPoints()

string_points = roi_points.getValue()

Hi all,

Using the idr-py package in python I have been extract images from the IDR succesfully. As far as I understand idr-py is a wrapper for the omero blitz-gateway to the IDR (please correct me if I’ve wrong). Now, firstly I’m struggling to find much decent documentation on using the idr-py api and the blitzgateway documentation either I can’t find or it’s slim (if anyone could help with that I’d grateful).

With this in mind I can’t seem to pull ROIs off of the IDR in a sensible format, see code above). Following the obvious trail of get functions, getImage on an ROI object fails # UnloadedEntityException: Object unloaded:object #0 (::omero::model::Image)
Using getPrimary shape leads down a trail where you get a coordinate pair string, I’m happy to parse this and make my own ROI masks from it, but it feels like I’ve gone the wrong way if this is what i’ll end up doing.

Any advice welcome on how to properly extract ROIs from IDR images.


Craig R

Hi Craig,

You can get coordinates for ROIs as shown at
(look under the heading “Retrieve ROIs linked to an Image”.

If you’re using Masks, you can get the png for a particular Shape ID using
which comes from this image:

The code that generates this mask can be found at (python 3).

Hope that helps?