Page 1 of 1

Out-of-bounds ROI creation

PostPosted: Tue Aug 09, 2011 11:50 am
by a.herbert
Hi,

I have been using Insight to create ROIs on my images and then use the 'Util scripts/Images_From_ROIs' script to extract new images.

This is find when the ROI is within the image. However in Insight it is possible to create an ROI that goes out of the bounds of the image by dragging the rectangle too far when creating the ROI. When I run the script I get an error like this:

Code: Select all
ERROR:blitz_gateway:Failed to getPlane() or getTile() from rawPixelsStore
Traceback (most recent call last):
  File "/home/omero/omero_dist/lib/python/omero/gateway/__init__.py", line 4579, in getTiles
    rawPlane = rawPixelsStore.getTile(z, c, t, x, y, width, height)
  File "/home/omero/omero_dist/lib/python/omero/gateway/__init__.py", line 2943, in wrapped
    return inner(*args, **kwargs)
  File "/home/omero/omero_dist/lib/python/omero/gateway/__init__.py", line 2885, in inner
    return f(*args, **kwargs)
  File "/home/omero/omero_dist/lib/python/omero_api_RawPixelsStore_ice.py", line 182, in getTile
    return _M_omero.api.RawPixelsStore._op_getTile.invoke(self, ((z, c, t, x, y, w, h), _ctx))
ApiUsageException: exception ::omero::ApiUsageException
{
    serverStackTrace = ome.conditions.ApiUsageException: X '320' greater than sizeX '256'.
    ...


I have fixed this by adding a simple boundary check to the ROI dimensions:

Code: Select all

    W = image.getSizeX()
    H = image.getSizeY()   

    ...

    for index, r in enumerate(rois):
        x,y,w,h, z1,z2,t1,t2 = r
        # Bounding box
        if x < 0: x = 0
        if y < 0: y = 0     
        if x + w > W: w = W - x
        if y + h > H: h = H - y


However I wanted to know if it is a bug that ROIs can be outside the dimensions of the image.

I am using OMERO 4.3.0.

Regards,

Alex

Re: Out-of-bounds ROI creation

PostPosted: Tue Aug 09, 2011 2:27 pm
by wmoore
Hi Alex,

I think there are valid use cases for ROIs that extend outside the image, so I don't think it's a bug in Insight that lets you save them. It's also very tricky to enforce this from a database point of view.
Having said that, I can't tell you that we've tested all the Insight measurement tool functionality with out-of-bounds ROIs, E.g. histograms, intensity statistics etc.

The fix that you've suggested for the Images_From_ROIs script is certainly useful. I'll add that to the current version.

Many thanks,

Will.

Re: Out-of-bounds ROI creation

PostPosted: Tue Aug 09, 2011 4:01 pm
by a.herbert
Hi Will,

Thanks for the info. I wanted to check since I was thinking that you may want an ROI outside of the image boundaries for certain functionality.

I guess my fix will only work if at least part of the ROI lies within the image. However a quick check of Insight shows that you cannot create an ROI entirely outside the image. I suppose you could do this programmatically though. In this case I think I'd be happy to live with the script throwing the exception. It will highlight something very wrong with the image ROIs.

Regards,

Alex