ome / omero-scripts

Core OMERO Scripts
https://pypi.org/project/omero-scripts/
12 stars 32 forks source link

Use script on other shapes #209

Open lguerard opened 1 year ago

lguerard commented 1 year ago

Hi all !

I wanted to the use the Images_From_ROIs script to crop my images on our OMERO, but was surprised to see that this is limited to rectangles as shown here:

https://github.com/ome/omero-scripts/blob/88219a3323685a575f92e689222b91b4e590da3c/omero/util_scripts/Images_From_ROIs.py#L146

I wanted to modify it to accept all types of shapes but couldn't find anything about getting the bounding box for any other shape, did I miss something ?

Thanks for your help !

will-moore commented 1 year ago

I'm afraid you'll need to handle each Shape separately. Create a function, e.g. getBoundingBox(shape) and implement that for each type of Shape. E.g. for PolyLine or Polygon, iterate through all the points and find min/max for X and Y. See https://omero.readthedocs.io/en/v5.6.7/developers/Python.html#rois under "Retrieve ROIs linked to an Image" For polygons and polyline parsing of the points string, see https://github.com/ome/omero-web/blob/ba072f151247df5b62768a0fbf37891675e2802d/omeroweb/webgateway/marshal.py#L390

lguerard commented 1 year ago

Thanks @will-moore for the pointers. Stupidly enough, I thought that it would be a simple getbbox like in Fiji. When I have time I'll look at implementing it !

In the meantime, I've also noticed that using the script on a 16bit image returns an 8bit image. Also the thumbnail looks weird and the image doesn't open, would you know why this would happen ? image

will-moore commented 1 year ago

I'm not sure what you're seeing there but the script works for me on a 16-bit image so I'm not sure it's the data-type. Can you test with a few different images and confirm whether you're seeing this issue on all 16-bit images but not on any others?