Cytomine-core icon indicating copy to clipboard operation
Cytomine-core copied to clipboard

Export Images with Annotations?

Open jacmarjorie opened this issue 7 years ago • 9 comments

Is there a way to download a whole image which would include the embedded annotations? I see that you can access the part of the image that has been annotated with the "crop" functionality, but am curious about pulling down the whole image with the annotations included.

Thanks!

jacmarjorie avatar Jul 12 '16 21:07 jacmarjorie

Hello, Sorry, we don't have this feature.

It is currently possible to extract binary masks for a specific region and a specific term but not for all term and all the image.

geektortoise avatar Aug 02 '16 07:08 geektortoise

Hello jacmarjorie,

Did you progress on this ?

As Renaud replied, it is not currently implemented as a complete web service.

But with our current API you can export bitmap images of any tile/masks, e.g.: (to get a 1000x1000 binary mask of the annotation term 528044 from the reviewed layer in the imageinstance 528460 at position (23181,14285): http://demo.cytomine.be/api/imageinstance/528460/window-23181-14285-1000-1000.png?mask=true&review=true&terms=528044 And the corresponding original image tile (without the annotation mask): http://demo.cytomine.be/api/imageinstance/528460/window-23181-14285-1000-1000.png

You might then rebuild in a client a whole image by fetching tiles exhaustively and merging them using some overlay/transparency. In Python you might be using vips library and its VImage object and insert function (e.g. like here: https://github.com/jcupitt/libvips/issues/354).

Does it help ?

rmaree avatar Aug 18 '16 14:08 rmaree

Thank you both for your responses.

At first, we were able to use crop masks: api/userannotation/$id/mask.$format to rebuild the complete mask that we need. However, we quickly ran into an issue with compression ratios affecting the accuracy of the masks. I can send you examples in a direct email of how an annotation mask looks in comparison to it's actual annotation. I believe this issue isn't in the demo version (it seems the demo is running an version of cytomine that is behind master). The compression ratio must be related to this: https://github.com/cytomine/Cytomine-core/blob/6462654309e5b2fe123f10c4026cc544a839907d/grails-app/services/be/cytomine/utils/geometry/SimplifyGeometryService.groovy.

We found we can get around the compression issue by using the /api/imageinstance/$id/window endpoint as you suggest with the mask=true. This actually allowed us to get the whole image assuming the right values were passed for width and height. However, we have ran into an issue where some annotations are not displayed. The annotations that fail to display on the window are in the database, have masks, etc. It just does not display on the binary mask window. Given this, we have to use the less accurate masks (due to the affects from compression ratios) to get information for that annotation. I can also send you examples of this in a personal email.

Thanks again!

jacmarjorie avatar Aug 18 '16 19:08 jacmarjorie

Yes please send more details to us about compression ratio, and missing binary masks.

rmaree avatar Aug 19 '16 09:08 rmaree

Without knowing the details of annotation mask extraction, did the issue mentioned in the previous two posts with annotations not being displayed resolve? (I am also interested in extracting annotations for a whole image)

sparrisable avatar Mar 24 '17 08:03 sparrisable

(Apologies for the late response on this). We were able to identify that an annotation will not appear in the /api/imageinstance/$id/window call if there is another annotation that only partly overlaps with another annotation. If your images do not have such annotations, then you should be able to extract whole images using the method I described in the second paragraph above. Good luck! Also, I am no longer on this project, but @burlinge maybe able to help point you to some examples if you run into problems.

jacmarjorie avatar Mar 24 '17 16:03 jacmarjorie

Thank you for your answer. After thinking some more about this, what I really would like is to read out the annotation data in text/vector data form and then generate the annotation masks outside of Cytomine.

I am inspecting the docker sql database for the annotations (there seem to be a user_annotation table) so that I can read out all the annotations for images at once.

I think that it should be possible to create a sql query to get all annotations but at the moment I am struggling with this since I am not familiar postgre or with the layout of the database.

I would happily take any suggestions for how to make such a sql query (I suspect it is straightforward if you know the database layout)

sparrisable avatar Apr 03 '17 18:04 sparrisable

Hi sparrisable,

To get all annotations created in an image in text/vector data, you might consider using our API. Please have a look here: http://doc.cytomine.be/display/DEVDOC/Rest+Api+Documentation For example this (you can add/remove filters): http://demo.cytomine.be/api/annotation.json?&project=528050&term=528044&users=263676&images=528132 Please also have a look at our Python/Java clients implementing functions accessing these services, e.g. in Python: https://github.com/cytomine/Cytomine-python-client/blob/master/client/examples/get_annotations.py Then you can also use individual get_annotation calls to get the full WKT geometry. Does it help ?

rmaree avatar Apr 03 '17 18:04 rmaree

This helps for sure. Much better to use your API to get the WKT geometry, thanks a lot.

sparrisable avatar Apr 04 '17 06:04 sparrisable