Page 1 of 1

[C++] Adding metadata for series

PostPosted: Tue Dec 13, 2016 11:30 am
by thomas_braun
Hi,

I'm in the process of writing an application which converts from a proprietary dataformat to OME-TIFF using the C++ libraries (ome-files-cpp 0.2.2, ome-common 5.3.2, bioformats 5.2.3).

I want to write multiple 2D images/datasets as series into one OME TIFF file.
This works, but I'm struggling to add specific metadata for each series

Code: Select all
for(auto dsn : matches)
      {
        // read each image dimensions from the dataset
        ReadImageDimensions(dsn, dims);

        // create meta data as we now know the image size
        shared_ptr<ome::files::CoreMetadata> meta = CreateMetaDataForImage(dims[0], dims[1]);

        meta->seriesMetadata.set("HDF5 Source Dataset", "some string");

        metadataStore->setImageID(ome::files::createID("Image", idx), idx);
        fillPixels(*metadataStore, *meta, idx);

        ome::xml::meta::OMEXMLMetadata& omexml(dynamic_cast<ome::xml::meta::OMEXMLMetadata&>(*metadataStore));
        ome::files::addMetadataOnly(omexml, idx);
        idx++;
      }


I've now looked at the generated TIFF file using
Code: Select all
ome-files info --omexml


Image: file_with_one_raw_image_raw_img.ome.tiff
Using reader: OME-TIFF (Open Microscopy Environment TIFF)
Reader setup took 00:00:00.083000

Filename = "/.../file_with_one_raw_image_raw_img.ome.tiff"
Used files = ["/.../file_with_one_raw_image_raw_img.ome.tiff"]

Reading core metadata
Series count = 1

Series #0:
Image count = 1
RGB = [false] ([1])
Interleaved = false
Indexed = false
Width = 3000
Height = 2000
SizeZ = 1 (effectively 1)
SizeT = 1 (effectively 1)
SizeC = 1 (effectively 1)
Thumbnail size = 128 × 85
Endianness = little
DimensionOrder = XYZTC (certain)
PixelType = uint16
Bits per Pixel = 16
MetadataComplete = true
ThumbnailSeries = false

Global metadata:
HDF5 File Version: 0.1
HDF5 Source File: /.../file_with_one_raw_image.h5
HDF5 Storage Server compilation timestamp: Jan 29 2016 17:50:06
UserComment: someComment

OME-XML metadata:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" UUID="urn:uuid:2cb9eadf-7f62-42f6-a81d-cd9095590a7a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/O ... 06/ome.xsd"><!-- Warning: this comment is within an OME-XML metadata block, which contains crucial dimensional parameters and other important metadata. Please edit cautiously (if at all), and back up the original data before doing so. For more information, see the OME-TIFF web site: http://www.openmicroscopy.org/site/supp ... /ome-tiff/ --><Image ID="Image:0"><Pixels BigEndian="false" DimensionOrder="XYZTC" ID="Pixels:0" Interleaved="false" SignificantBits="16" SizeC="1" SizeT="1" SizeX="3000" SizeY="2000" SizeZ="1" Type="uint16"><Channel Color="-1" ID="Channel:0:0" SamplesPerPixel="1"/><TiffData FirstC="0" FirstT="0" FirstZ="0" IFD="0" PlaneCount="1"><UUID FileName="file_with_one_raw_image_raw_img.ome.tiff">urn:uuid:2cb9eadf-7f62-42f6-a81d-cd9095590a7a</UUID></TiffData><Plane TheC="0" TheT="0" TheZ="0"/></Pixels></Image><StructuredAnnotations><XMLAnnotation ID="Annotation:0"><Value><OriginalMetadata xmlns=""><Key xmlns="">HDF5 File Version</Key><Value xmlns="">0.1</Value></OriginalMetadata></Value></XMLAnnotation><XMLAnnotation ID="Annotation:1"><Value><OriginalMetadata xmlns=""><Key xmlns="">HDF5 Source File</Key><Value xmlns="">/.../file_with_one_raw_image.h5</Value></OriginalMetadata></Value></XMLAnnotation><XMLAnnotation ID="Annotation:2"><Value><OriginalMetadata xmlns=""><Key xmlns="">HDF5 Storage Server compilation timestamp</Key><Value xmlns="">Jan 29 2016 17:50:06</Value></OriginalMetadata></Value></XMLAnnotation><XMLAnnotation ID="Annotation:3"><Value><OriginalMetadata xmlns=""><Key xmlns="">UserComment</Key><Value xmlns="">someComment</Value></OriginalMetadata></Value></XMLAnnotation><XMLAnnotation ID="Annotation:4"><Value><OriginalMetadata xmlns=""><Key xmlns="">HDF5 File Version</Key><Value xmlns="">0.1</Value></OriginalMetadata></Value></XMLAnnotation><XMLAnnotation ID="Annotation:5"><Value><OriginalMetadata xmlns=""><Key xmlns="">HDF5 Source File</Key><Value xmlns="">/.../file_with_one_raw_image.h5</Value></OriginalMetadata></Value></XMLAnnotation><XMLAnnotation ID="Annotation:6"><Value><OriginalMetadata xmlns=""><Key xmlns="">HDF5 Storage Server compilation timestamp</Key><Value xmlns="">Jan 29 2016 17:50:06</Value></OriginalMetadata></Value></XMLAnnotation><XMLAnnotation ID="Annotation:7"><Value><OriginalMetadata xmlns=""><Key xmlns="">UserComment</Key><Value xmlns="">someComment</Value></OriginalMetadata></Value></XMLAnnotation></StructuredAnnotations></OME>
OME-XML validation successful


but my metadata series entry seems to be not there.

Any hints what I'm doing wrong?

Re: [C++] Adding metadata for series

PostPosted: Wed Dec 14, 2016 11:53 am
by rleigh
The "Series Metadata" in CoreMetadata is filled when reading an image; this is typically reader-specific key-value pairs for format-specific metadata which isn't represented by the OME-XML data model, and is for the most part completely independent of the OME-XML metadata other than setting them from OriginalMetadata annotations where present. It's not (currently) used when writing; the series metadata is not used at all.

This is certainly something we can change; we could make the MetadataTools fill functions create OriginalMetadata annotations from these core metadata objects.

I created https://trello.com/c/mJfifiAq/54-save-s ... adatastore to track this.

For now, I would suggest looking at creating a custom XML Annotation using e.g. OriginalMetadataAnnotation Java or C++). An example of how to use it is here; a similar thing could be done with OME Files C++. However, we're unhappy with the usability of this, and are currently investigating a much more general and user-friendly way of working with custom annotations, which we hope to have in place for the upcoming OME Files C++ 0.3.0 release. This should make using the model much more transparent.


Kind regards,
Roger

Re: [C++] Adding metadata for series

PostPosted: Mon Feb 06, 2017 6:09 pm
by thomas_braun
Thanks Roger. I went down the route you suggested.