Page 1 of 1

retrieve tags assocaited with an image

PostPosted: Mon Oct 22, 2012 11:42 am
by jiez
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

Re: retrieve tags assocaited with an image

PostPosted: Tue Oct 23, 2012 6:38 pm
by jburel
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

Re: retrieve tags assocaited with an image

PostPosted: Tue Oct 30, 2012 5:31 pm
by jiez
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.

Re: retrieve tags assocaited with an image

PostPosted: Wed Oct 31, 2012 9:18 am
by jburel
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

Re: retrieve tags assocaited with an image

PostPosted: Thu Nov 01, 2012 4:22 pm
by jiez
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

Re: retrieve tags assocaited with an image

PostPosted: Thu Nov 01, 2012 4:53 pm
by jiez
forget to ask where can I find the reference about ome.model classes, especially about annotations.

thanks.

Re: retrieve tags assocaited with an image

PostPosted: Fri Nov 02, 2012 9:37 am
by wmoore

Re: retrieve tags assocaited with an image

PostPosted: Mon Nov 05, 2012 1:47 pm
by jiez
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