We're Hiring!

retrieve tags assocaited with an image

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

retrieve tags assocaited with an image

Postby jiez » Mon Oct 22, 2012 11:42 am

Hi,

I searched a little bit but can't find an example of how to retrieve the custom tags (input by insight TAG functions) associated with an image.

From the omero_client API (JAVA), I can retrieve all images based on userIds and some other custom inputs including descriptions, while I have no ideas how to retrieve other annotated information with these images such as tags, paths or TIFF metadata.

I am not sure whether IMetadata or IQuery can help. Can anyone give me an example (JAVA) of how to retrieve these information when image Id is known?

many thanks.

jiez
jiez
 
Posts: 16
Joined: Mon Oct 22, 2012 11:24 am

Re: retrieve tags assocaited with an image

Postby jburel » Tue Oct 23, 2012 6:38 pm

Hi Jiez

To retrieve all the annotations (e.g. tags comments etc) linked to a given image, you could use the loadAnnotations method using IMetadata.
If you only want to load a given type of annotation, you can specify it as a parameter.
When the image is imported, a "companion" file containing all the metadata from the image is created and linked to the image. This is a File Annotation (name= "original_metadata.txt) with a specific namespace openmicroscopy.org/omero/import/companionFile.

If you want to read image metadata parsed at import and stored in the database (metadata supported by the OME model), various methods are also available from IMetadata e.g. loadInstrument.

Hope this helps

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: retrieve tags assocaited with an image

Postby jiez » Tue Oct 30, 2012 5:31 pm

many thanks. jburel . So far I manage to get the 'IObject' of all annotations with following code:


IMetadataPrx metadataService = myEntry.getMetadataService();

ArrayList imageIds = new ArrayList();
Long image1 = Long.valueOf(11701); // image id 1 ;
Long image2 = Long.valueOf(11702); // image id 2;
imageIds.add( image1);
imageIds.add( image2);

ArrayList annotationTypes = new ArrayList();
annotationTypes.add( (String)("TagAnnotation"));

ArrayList annotatorIds =new ArrayList();
Parameters parameters = new Parameters();

String rootType = "Image";
Map <Long, List <IObject> > idSetMap = metadataService.loadAnnotations(rootType, imageIds, annotationTypes, annotatorIds, parameters);

Iterator itr = idSetMap.keySet().iterator();
while (itr.hasNext())
{}


can you remind me how to process the value of idSetMap (IObject) please? I cannot find the reference about ome.model.* online.
jiez
 
Posts: 16
Joined: Mon Oct 22, 2012 11:24 am

Re: retrieve tags assocaited with an image

Postby jburel » Wed Oct 31, 2012 9:18 am

Hi Jiez
Code: Select all
Map <Long, List <IObject>  > idSetMap = metadataService.loadAnnotations(rootType, imageIds, annotationTypes, annotatorIds, parameters);
         
Iterator<IObject>   i = idSetMap.keySet().iterator();

TagAnnotation tag;
String value;
          while (i.hasNext()) {
          //since you are only loading tags
           tag = (TagAnnotation) i.next(); // If you load more than one type, check the type of the IObjet.
           //to get the text
           RString text = tag.getTextValue(); //can be null so you need to check
           if (text != null)  value = text.getValue();
           //To get the description of the tag
           RString desc = tag.getDescription(); //can be null so you need to check
          }


Hope this helps.

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: retrieve tags assocaited with an image

Postby jiez » Thu Nov 01, 2012 4:22 pm

thanks Jmaria.

Exactly following your guide causes <long> type problem, so I modify a little bit:


IMetadataPrx metadataService = myEntry.getMetadataService();

ArrayList imageIds = new ArrayList();
Long image1 = Long.valueOf(1227); // image 1 with some tags;
Long image2 = Long.valueOf(1247); // image 2 without tags;
imageIds.add( image1);
imageIds.add( image2);

ArrayList annotationTypes = new ArrayList();
annotationTypes.add( (String)(""ome.model.annotations.TagAnnotation""));

ArrayList annotatorIds =new ArrayList();
Parameters parameters = new Parameters();

String rootType = "Image";
Map <Long, List <IObject> > idSetMap = metadataService.loadAnnotations(rootType, imageIds, annotationTypes, annotatorIds, parameters);

Iterator <Long> itr = idSetMap.keySet().iterator();
String tag_value = "";
String tag_descrp ="";
System.out.print("meta data: .\n\n");
while (itr.hasNext())
{
Long ids = (Long) itr.next();
System.out.print("image id is :"+Long.toString(ids)+"*.\n\n");
Iterator <IObject> j = idSetMap.get(ids).iterator();
while (j.hasNext())
{
String tag_= j.next().getClass().getName();
System.out.print("iobject class name :"+tag_ +"*.\n\n");
// TagAnnotation tag = (TagAnnotation) j.next();

}//

Here is the output :

meta data: .

image id is :1247*.

image id is :1227*.

iobject class name :omero.model.TagAnnotationI*.

iobject class name :omero.model.TagAnnotationI*.

IF ' TagAnnotation tag = (TagAnnotation) j.next(); ' is activated, then error comes up as

inconvertible types
found : omero.model.IObject
required: ome.model.annotations.TagAnnotation
TagAnnotation tag = (TagAnnotation) j.next();
^
.

can you help me further on this? thanks a lot.

jiez
jiez
 
Posts: 16
Joined: Mon Oct 22, 2012 11:24 am

Re: retrieve tags assocaited with an image

Postby jiez » Thu Nov 01, 2012 4:53 pm

forget to ask where can I find the reference about ome.model classes, especially about annotations.

thanks.
jiez
 
Posts: 16
Joined: Mon Oct 22, 2012 11:24 am

Re: retrieve tags assocaited with an image

Postby wmoore » Fri Nov 02, 2012 9:37 am

User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: retrieve tags assocaited with an image

Postby jiez » Mon Nov 05, 2012 1:47 pm

many thanks. Now it works.

What confused me was the the TagAnnotation class. Previously I used ome.model.annotations.Annotation and ome.model.annotations.TagAnnotation. Now I import omero.model.Annotation and omero.model.TagAnnotation.

jiez
jiez
 
Posts: 16
Joined: Mon Oct 22, 2012 11:24 am


Return to Developer Discussion

Who is online

Users browsing this forum: Google [Bot] and 1 guest