Skip Headers
Oracle® interMedia User's Guide
10g Release 2 (10.2)

Part Number B14302-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

5 Working with Metadata in Images

Image files can contain information about the content of the images, the image rasters, and image metadata. In general, data about data is referred to as metadata. In this case, metadata refers to additional information about the actual images, which is stored in the image files along with the images.

5.1 Metadata Concepts

Several types of metadata can be stored in an image file, and each type can serve a different purpose. One type, technical metadata, is used to describe an image in a technical sense. For example, technical metadata can include attributes about an image, such as its height and width, in pixels, or the type of compression used to store it. Another type, content metadata, can further describe the content of an image, the name of the photographer, and the date and time when a photograph was taken.

Metadata is stored in image files using a variety of mechanisms. Digital cameras and scanners automatically insert metadata into the images they create. Digital photograph processing applications like Adobe Photoshop allow users to add or edit metadata to be stored with the image. Annotating digital images with additional metadata is a common practice in photographic and news gathering applications and for image archiving usages, as well as at the consumer level.

Storing metadata together with image data in the same containing file provides encapsulation. With encapsulation, both types of data can be shared and exchanged reliably as one unit. Metadata that is stored in the image file format is referred to as embedded metadata.

5.2 Oracle interMedia Image Metadata Concepts

For a large number of image file formats, Oracle interMedia ("interMedia") can extract and manage a limited set of metadata attributes. These attributes include: height, width, contentLength, fileFormat, contentFormat, compressionFormat, and mimeType. For a limited number of image file formats, interMedia can extract a rich set of metadata attributes. This metadata is represented in schema-based XML documents. These XML documents can be stored in a database, indexed, searched, updated, and made available to applications using the standard mechanisms of Oracle Database.

interMedia can also write or embed metadata supplied by users into a limited number of image file formats. The application provides the metadata as a schema-based XML document. interMedia processes the XML document and writes the metadata into the image file.

5.3 Image File Formats

interMedia supports metadata extraction and metadata embedding for the GIF, TIFF, and JPEG file formats. See Oracle interMedia Reference for information about the image file formats supported by interMedia.

5.4 Image Metadata Formats

The term image metadata format refers to the standard protocols and techniques used to store image metadata within an image file. The following subsections describe the embedded image metadata formats supported by interMedia:

5.4.1 EXIF

The Exchangeable Image File Format (EXIF) is the standard for image file storage for digital still cameras. It was developed by the Japan Electronic Industry Development Association (JEIDA) as a standard way of storing images created by digital cameras as well as metadata about the images. EXIF image metadata can be stored in TIFF and JPEG format images. interMedia supports the extraction of EXIF metadata from TIFF and JPEG file formats.

5.4.2 IPTC–IIM

The International Press Telecommunications Council-Information Interchange Model (IPTC-IIM) Version 4 is a standard developed jointly by the International Press Telecommunications Council and the Newspaper Association of America. This metadata standard is designed to capture information that is important to the activities of news gathering, reporting, and publishing. These information records are commonly referred to as IPTC tags.

The use of embedded IPTC tags in image file formats became widespread with the use of the Adobe Photoshop tool for image editing. IPTC metadata can be stored in TIFF and JPEG format images. interMedia supports the extraction of IPTC metadata from TIFF and JPEG file formats.

5.4.3 XMP

The Extensible Metadata Platform (XMP) is a standard metadata format, developed by Adobe, for the creation, processing, and interchange of metadata in a variety of applications. XMP uses Resource Description Framework (RDF) technology for data modeling. XMP also defines how the data model is serialized (converted to a byte stream), and embedded within an image file. interMedia supports the extraction of XMP metadata from GIF, TIFF, and JPEG file formats. interMedia also supports writing XMP data packets into GIF, TIFF, and JPEG file formats.

For more information about XMP, see the Adobe Systems Incorporated Web site at

http://www.adobe.com/

For more information about RDF, see the Resource Description Framework Web page on the World Wide Web Consortium Web site at

http://www.w3.org/RDF/

5.5 Representing Metadata Outside Images

Once metadata has been extracted from the binary image file, the next step is to represent the metadata in a form that can be easily stored, indexed, queried, updated, and presented. interMedia returns image metadata in XML documents. These documents are based on XML schemas that interMedia registers with the database. Each type of image metadata has a separate XML schema. These XML schemas are used by the metadata methods of the ORDImage object type. See Oracle interMedia Reference for complete definitions of the XML schemas supported by interMedia.

The XML documents can be stored in XMLType columns within the database. These documents are easily searched and processed using the wide range of standards-based XML technologies provided by Oracle XML DB. (See Oracle XML DB Developer's Guide for more information.)

5.6 Oracle interMedia Image Metadata Examples

The following examples of metadata extraction and embedding make use of the photos table. The photos table is defined by the Photo Album sample application. The implementation of the Photo Album sample application is defined in the PL/SQL package named PHOTO_ALBUM. See Chapter 3 for a complete description of the interMedia PL/SQL Web Toolkit Photo Album sample application.

The photos table stores two instances of an image: the full-size photograph and a thumbnail image. This table can also store up to four different image metadata documents. These documents are stored in the columns named metaORDImage, metaEXIF, metaIPTC, and metaXMP, and represent image metadata from the ORDImage, EXIF, IPTC, and XMP metadata formats, respectively. The metadata columns are of type XMLType, and they are bound to the corresponding metadata XML schemas that interMedia provides.

5.6.1 Creating a Table for Metadata Storage

Before you can extract or embed metadata, you must create the table and columns where the metadata will be stored. The following PL/SQL code segment creates the photos table with four XMLTYPE columns (metaORDImage, metaEXIF, metaIPTC, and metaXMP) to store each type of image metadata, and two ORDIMAGE columns (image and thumb) for the original image and the thumbnail image, respectively. Each metadata column is bound to its corresponding metadata schema. For example, the metaEXIF column is bound to the XML schema stored at http://xmlns.oracle.com/ord/meta/exif, and is defined as the XML element exifMetadata.

For ease of reference, the code statements where the image metadata columns are defined and bound to XML schemas are highlighted in bold.

--
-- Create the PHOTOS table
--
CREATE TABLE photos( id           NUMBER PRIMARY KEY,
                     description  VARCHAR2(40) NOT NULL,
                     metaORDImage XMLTYPE,
                     metaEXIF     XMLTYPE,
                     metaIPTC     XMLTYPE,
                     metaXMP      XMLTYPE,
                     image        ORDSYS.ORDIMAGE,
                     thumb        ORDSYS.ORDIMAGE )
LOB(image.source.localdata)  -- storage images with 32K chunk
  STORE AS (chunk 32k)
LOB(thumb.source.localdata)  -- but the thumbnails with only 16k
  STORE AS (chunk 16k)
-- and bind the XMLType columns to the interMedia metadata schemas
XMLType COLUMN metaORDImage
  XMLSCHEMA "http://xmlns.oracle.com/ord/meta/ordimage"
  ELEMENT "ordImageAttributes"
XMLType COLUMN metaEXIF
  XMLSCHEMA "http://xmlns.oracle.com/ord/meta/exif"
  ELEMENT "exifMetadata"
XMLType COLUMN metaIPTC
  XMLSCHEMA "http://xmlns.oracle.com/ord/meta/iptc"
  ELEMENT "iptcMetadata"
XMLType COLUMN metaXMP
  XMLSCHEMA "http://xmlns.oracle.com/ord/meta/xmp"
  ELEMENT "xmpMetadata";

5.6.2 Extracting Image Metadata

The following PL/SQL procedure extracts metadata from an image and stores it in the specified columns in the photos table you created. This procedure demonstrates the getMetadata( ) method, which returns an array of XML documents. The root element of each document is examined to determine the metadata type. The UPDATE statement stores the documents in the corresponding columns in the photos table.

For ease of reference, the code statement where the getMetadata( ) method is called is highlighted in bold.

--
-- fetch the metadata and sort the results
--
PROCEDURE extractMetadata(inID IN INTEGER)
IS
  img ORDSYS.ORDIMAGE;
  metav XMLSequenceType;
  meta_root VARCHAR2(40);
  xmlORD XMLType;
  xmlXMP XMLType;
  xmlEXIF XMLType;
  xmlIPTC XMLType;
 
BEGIN
 
-- select the image
SELECT image
INTO img
FROM PHOTOS
WHERE id = inID;

-- extract all the metadata
metav := image.getMetadata( 'ALL' );
 
-- process the result array to discover what types of metadata were
returned
FOR i IN 1..metav.count() LOOP
  meta_root := metav(i).getRootElement();
  CASE meta_root
    WHEN 'ordImageAttributes' THEN xmlORD := metav(i);
    WHEN 'xmpMetadata' THEN xmlXMP := metav(i);
    WHEN 'iptcMetadata' THEN xmlIPTC := metav(i);
    WHEN 'exifMetadata' THEN xmlEXIF := metav(i);
    ELSE NULL;
  END CASE;
END LOOP;

-- Update metadata columns
--
UPDATE photos
SET metaORDImage = xmlORD,
    metaEXIF = xmlEXIF,
    metaIPTC = xmlIPTC,
    metaXMP = xmlXMP
WHERE id = inID;
 
END extractMetadata;

5.6.3 Embedding Image Metadata

The following PL/SQL procedure demonstrates the putMetadata( ) method. This procedure accepts six arguments. The entry_id argument identifies the image in the photos table to be updated. The remaining arguments (title, creator, date, description, and copyright) are strings that will be formatted into an XMP packet and embedded within the target image.

This example creates an XML document instance based on the interMedia XML schema for XMP metadata. (This schema is preregistered with Oracle XML DB. See Oracle XML DB Developer's Guide for more information.) The schema for XMP metadata defines a single, global element <xmpMetadata>. The <xmpMetadata> element contains a single, well-formed RDF document. The RDF document contains a single <RDF> element, which is derived from the rdf namespace. This RDF document is constructed using elements defined by the Dublin Core Schema.

The call to the putMetadata( ) method embeds the metadata document into the image file. The UPDATE statement stores the new image and the new metadata back in the photos table.

For ease of reference, the code statement where the putMetadata( ) method is called is highlighted in bold.

--
-- write the metadata to the image
--
PROCEDURE write_metadata( entry_id IN VARCHAR2,
                          title IN VARCHAR2,
                          creator IN VARCHAR2,
                          date IN VARCHAR2,
                          description IN VARCHAR2,
                          copyright IN VARCHAR2 )
IS
  img ORDSYS.ORDImage;
  xmp XMLType;
  buf VARCHAR2(5000);
BEGIN
-- select the image
SELECT image
INTO img
FROM PHOTOS
WHERE id = entry_id FOR UPDATE;

-- Create the XMP packet it must be schema valid
-- to "http://xmlns.oracle.com/ord/meta/xmp"
-- and contain an <RDF> element. This example uses
-- the Dublin Core schema.

/* An example XML instance document
 
<xmpMetadata xmlns="http://xmlns.oracle.com/ord/meta/xmp" 
              xsi:schemaLocation="http://xmlns.oracle.com/ord/meta/xmp 
              http://xmlns.oracle.com/ord/meta/xmp" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Description about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
      <dc:title>A Winter Day<dc:title>
      <dc:creator>Frosty S. Man</dc:creator>
      <dc:date>21-Dec-2004</dc:date>
      <dc:description>a sleigh ride</dc:description>
      <dc:copyright>North Pole Inc.</dc:copyright>
    </rdf:Description>
  </rdf:RDF>
</xmpMetadata>
 
*/
 
buf := '<xmpMetadata xmlns="http://xmlns.oracle.com/ord/meta/xmp"
         xsi:schemaLocation="http://xmlns.oracle.com/ord/meta/xmp
         http://xmlns.oracle.com/ord/meta/xmp"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description about="" xmlns:dc="http://purl.org/dc/elements/1.1/">';
 
IF title IS NOT NULL THEN
  buf := buf || '<dc:title>' || htf.escape_sc(title) || '</dc:title>';
END IF;
 
IF creator IS NOT NULL THEN
  buf := buf || '<dc:creator>' || htf.escape_sc(creator)
             || '</dc:creator>';
END IF;
IF date IS NOT NULL THEN
  buf := buf || '<dc:date>' || htf.escape_sc(date)
             || '</dc:date>';
END IF;
IF description IS NOT NULL THEN
  buf := buf || '<dc:description>' || htf.escape_sc(description)
             || '</dc:description>';
END IF;
IF copyright IS NOT NULL THEN
  buf := buf || '<dc:copyright>' || htf.escape_sc(copyright)
             || '</dc:copyright>';
END IF;
 
buf := buf || '
  </rdf:Description>
  </rdf:RDF>
  </xmpMetadata>';

-- create the XML document
xmp := XMLType.createXML(buf, 'http://xmlns.oracle.com/ord/meta/xmp');
 
-- write the metadata
img.putMetadata( xmp, 'XMP' );
 
-- update the image
UPDATE photos
SET image = img,
    metaXMP = xmp
WHERE id = entry_id;
 
END write_Metadata;

5.7 Metadata References

The following Web sites provide information about standards and technologies related to working with metadata in images.

5.8 Extracting and Mapping DICOM Metadata Attributes in Images

The Digital Imaging and Communications in Medicine (DICOM) feature allows interMedia to recognize standalone DICOM objects and extract the set of attributes related to patient, study, series, and equipment. Recognizing a DICOM object means that interMedia can determine whether given binary data represents a standalone DICOM object. If it does, interMedia can extract DICOM metadata from that DICOM object. The data can be stored as the content of an ORDImage object, or directly in a BLOB or a BFILE.

DICOM objects are objects that can store different types of data. Examples include patient administration information, waveforms, images, slices of 3-D volumes, video segments, and time-variant 3-D volumes. A standalone DICOM object must have a file header that conforms to the DICOM standard.

The DICOM standard was initiated by the American College of Radiology (ACR) to enhance the connectivity of radiological devices. Before DICOM become a widely adopted standard, each manufacturer had its own proprietary image format and communication protocol, making it almost impossible to produce third-party software to manage or study medical data. Nor was it possible to connect devices from different manufacturers. In 1985, the American College of Radiology and the National Electrical Manufacturers Association (NEMA) jointly published a medical imaging and communication standard, named the ACR-NEMA standard, to address this problem. In 1993 the standard was revised and renamed as DICOM (Version 3.0). Since then, the DICOM standard has become the dominant standard for radiology imaging and communication. All major manufacturers conform to this standard. Today, any software component can take DICOM data from any manufacturer and manage the data with a uniform interface.

See Oracle interMedia Reference for details about the DICOM methods, encoding rules, image format, and exceptions supported by interMedia.

5.9 DICOM Image File Format

interMedia supports metadata extraction for the DICM image file format. DICM is the interMedia designation for the Digital Imaging and Communications in Medicine format. See Oracle interMedia Reference for more information about the image file formats supported by interMedia.

5.10 Oracle interMedia DICOM Image Metadata Example

The following example of DICOM metadata extraction makes use of the medicalImages table, which is defined in the sample PL/SQL code segments described in the following subsections.

The medicalImages table stores two instances of an image: the full-size photograph and a thumbnail image. This table can also store one image metadata document. This document is stored in the column named metadata, and represents DICOM image metadata from the DICM metadata format. The metadata column is of type XMLType, and it is bound to the corresponding metadata XML schema that interMedia provides.

5.10.1 Creating a Table for DICOM Metadata Storage

Before you can extract DICOM metadata, you must create the table and column where the metadata will be stored. The following PL/SQL code segment creates the medicalImages table with one XMLTYPE column (metadata) to store the DICOM image metadata, and two ORDIMAGE columns (image and thumb) for the original image and the thumbnail image, respectively. The metadata column is bound to the XML schema stored at http://xmlns.oracle.com/ord/meta/dicomImage, and is defined as the XML element DICOM_IMAGE.

For ease of reference, the code statements where the image metadata column is defined and bound to the XML schema are highlighted in bold.

create table medicalImages(id number primary key, 
                           description VARCHAR2(40),
                           metadata XMLType,
                           image ORDSYS.ORDIMAGE,
                           thumb ORDSYS.ORDIMAGE)
LOB (image.source.localdata) -- store images with 32K chunk
  STORE AS (chunk 32K)
LOB (thumb.source.localdata) -- but the thumbnails with only 16K
  STORE AS (chunk 16K)
-- and bind the XMLType columns to the interMedia metadata columns
XMLType column metadata
  XMLSCHEMA "http://xmlns.oracle.com/ord/meta/dicomImage"
  ELEMENT "DICOM_IMAGE";

5.10.2 Extracting DICOM Image Metadata

The following PL/SQL procedure extracts DICOM metadata from an image and stores it in the specified column in the medicalImages table you created. This procedure demonstrates the getDicomMetadata( ) method, which returns an XML document. The UPDATE statement stores the document in the corresponding column in the medicalImages table.

For ease of reference, the code statement where the getDicomMetadata( ) method is called is highlighted in bold.

--
PROCEDURE extractDicomMetadata(inID INTEGER)
IS
   local_image ORDSYS.ORDIMAGE;
   local_id INTEGER;
   dicom_metadata XMLType := NULL;
BEGIN 
   SELECT image INTO local_image FROM medicalImages WHERE id = inID;
   -- extract DICOM metadata
   dicom_metadata := local_image.getDicomMetadata('imageGeneral');
   IF (dicom_metadata IS NULL) THEN
      DBMS_OUTPUT.PUT_LINE('metadata is NULL');
   ELSE
      UPDATE medicalImages SET metadata = dicom_metadata where id = inID;
   END IF;
   -- let us print the namespace of the XML document containing the
   -- dicom metadata that we just extracted
   DBMS_OUTPUT.PUT_LINE('namespace: ' || dicom_metadata.getNamespace());
 
END extractDicomMetadata;
--

5.11 DICOM References

The following Web sites provide information about medical imaging standards and issues related to DICOM.