Today we posted an updated MetadataPolicy.xml configuration file to support more image metadata fields when using the IMM Media Services to extract metadata from a JPEG or TIFF image. Download the latest cersion of the file and replace the existing one in the folder:

%Program Files%/Microsoft Interactive Media Manager\Microsoft Interactive Media Manager\Media Services\Metadata

The updates include support for more EXIF, TIFF, and XMP metadata fields that are commonly found.

It’s very useful to spend a few moments to understand how the metadata policy file works, if you need to extend it to extract metadata fields that may not be standard. You can easily edit this file and just save it back and it will be used immediately on the next query to the Image endpoint’s GetMetadata method.

The MetadataPolicy.xml file is modeled after the default Vista metadata policy in how it chooses what metadata to parse from an image file. You will notice that it is grouped into Policy Groups. Each Group defines a prioritized list of metadata paths to attempt to extract metadata from a file. IMM MediaServices uses this policy file to determine which path to attempt first and once it gets a hit, it will stop processing that Policy Group and return the results in RDF format using the property name defined in the immPredicate attribute of the Policy element.

There are lots of tools out there to use to view the existing metadata on your image files and help determine which ones to add to the policy document.  Here’s a couple of my favorite tools.

WIC EXPLORER

A great tool for helping out with image metadata and our MetadataPolicy file is the WIC Explorer which is in the Windows Imaging Component Code Samples and Tools. You can download it from here.

The WIC Explorer lets you view a tree of the metadata extracted in the files.  You can use the “Metadata Values” decimal (in Green below) to extract the metadata by setting the appropriate path in MetadataPolicy.xml file.

clip_image001

 

EXIF TOOL

Another handy tool is ExifTool by Phil Harvey. It is great for getting a dump from a file of available metadata in XMP format. http://www.sno.phy.queensu.ca/~phil/exiftool/

Drop it in your Windows folder, rename it to just “exiftool.exe” and run it like this to get an .xmp file in RDF format. Great for debugging.

c:\Content>exiftool 068.JPG -o -s %d%f.xmp

Also, just run the console like this to get a dump of metadata and field names.

c:\Content>exiftool 068.JPG –s

Updating Ontology to Support New Properties

Once you have located and added the new properties to the MetadataPolicy.xml file you will need to update your Owl Ontology’s ImageEssenceFormat class to have the new property restrictions.  In the current version of the IMM 2.0 Core Ontology, only the following properties are defined on the ImageEssenceFormat.  If you want to use other properties in your code, you will need to add more property restrictions to this class and then regenerate your own custom ontology assemblies for use in .NET development.

Default Properties of ImageEssenceFormat on the IMM Core 2.0 Ontology.

  • imm:ResolutionX
  • imm:ResolutionY
  • imm:Codec
  • imm:BitDepth
  • MicrosoftPhoto:CameraSerialNumber
  • MicrosoftPhoto:DateAcquired
  • MicrosoftPhoto:FlashManufacturer
  • MicrosoftPhoto:FlashModel
  • MicrosoftPhoto:LastKeywordIPTC
  • MicrosoftPhoto:LastKeywordXMP
  • MicrosoftPhoto:LensManufacturer
  • MicrosoftPhoto:LensModel
  • MicrosoftPhoto:Rating
  • MicrosoftPhoto:RatingPercent
  • dc:Subject

 

To extend the ImageEssenceFormat Class, you simply create a new custom ontology (or if you already defined one use that one), and then you add restrictions to the ImageEssenceFormat class.

First open or create a new OWL document. Define a new Ontology element and import the IMM Core 2.0 ontology from the web.

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:owl=http://www.w3.org/2002/07/owl# 
xmlns:rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns#
xmlns:rdfs
="http://www.w3.org/2000/01/rdf-schema#"> <rdf:Description rdf:about="foo:MyCustomOntology"> <rdf:type> <rdf:Description rdf:about="http://www.w3.org/2002/07/owl#
Ontology"
/> </rdf:type> <rdfs:comment>My Custom Ontology example for extending
ImageEssenceFormat</rdfs:comment> <owl:imports> <rdf:Description rdf:about="http://schemas.microsoft.com/imm/2.0/core/"/> </owl:imports> <owl:versionInfo>1.0</owl:versionInfo> </rdf:Description> </rdf:RDF>

First you need to define the new property that you want to add. In this case, I am adding the XMP Rating property as a new DatatypeProperty of type integer.

<rdf:Description rdf:about="http://ns.adobe.com/xap/1.0/Rating">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#
DatatypeProperty"
/>
        <rdfs:comment>A number that indicates a document’s status relative to
other documents, used to organize documents in a file
browser. Values are user-defined within an application defined
range.</rdfs:comment>
        <rdfs:label>Rating</rdfs:label>
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
</rdf:Description>

Next you need to add the property as a restriction on the ImageEssenceFormat class.

<rdf:Description rdf:about="http://schemas.microsoft.com/imm/2.0/core/
ImageEssenceFormat"
>
    <rdfs:subClassOf>
            <rdf:Description>
                <owl:maxCardinality rdf:datatype="http://www.w3.org/
2001/XMLSchema#nonNegativeInteger"
>1</owl:maxCardinality>
                <owl:onProperty>
                    <rdf:Description rdf:about="http://ns.adobe.com/
xap/1.0/Rating"
/>
                </owl:onProperty>
                <rdf:type>
                    <rdf:Description rdf:about="http://www.w3.org/2002/
07/owl#Restriction"
/>
                </rdf:type>
            </rdf:Description>
        </rdfs:subClassOf>
 
 
</rdf:Description>

 

Now, if I regenerate my ontology class using the Visual Studio tools, I will have a new Rating property on my ImageEssenceFormat class. I can now deserialize the RDF/XML from the GetMetadata call to Media Services and it will populate this new Rating property if the image has an XMP Rating value stored on it.