Number of instances in ROIs doesnt change even after deleting a shape

Hi

I have followed your tutorial (OMERO Python language bindings — OMERO 5.6.1 documentation) to use Python to delete a shape for an image in the omero server. I was able to successfully delete the shape, but the number of ROIs in the web UI doesn’t change.
Here is a snapshot attached. Could you look into it and help me out here?
Its okay if you just point out where I need to do the change in the omero-iviewer for the update.
image

Relevant code:
result = roi_service.findByImage(imageId, None)
for roi in result.rois:
for s in roi.copyShapes():
# Find and remove the Shape we added above
if s.getTextValue() and s.getTextValue().getValue() == “test-Ellipse”:
print(“Removing Shape from ROI…”)
roi.removeShape(s)
roi = updateService.saveAndReturnObject(roi)

Best Regards
Vignesh

It looks like you really want to delete the ROI itself.
An ROI is a container for 1 or more Shapes. By deleting the Shape, you still have an empty ROI (which doesn’t show up in the iviewer UI).

You can delete ROIs with conn.deleteObjects().
For example, to delete all the ROIs on an Image:

roi_ids = [roi.id.val for roi in result.rois]
conn.deleteObjects("Roi", roi_ids)

Hope that helps,

Will.

Ahh… Understood… Thanks for the clue. I was able to delete the ROI object containing a shape, but not the empty ROI object. if i need to delete the empty ROI, my code isnt detecting the roi. Any tips?

Best
Vignesh

Ah - interesting. It seems that roi_service.findByImgae() ignores ROIs with no shapes.
You can use the query service to lookup ROIs for an image:

query = "select roi from Roi as roi where roi.image=%s" % imageId
rois = conn.getQueryService().findAllByQuery(query, None)
roi_ids = [roi.id.val for roi in rois]

Then delete them as before.

Regards,
Will.