Oracle Visual Information Retrieval User's Guide and Reference
Release 8.1.7

Part Number A85335-01

Library

Product

Contents

Index

Go to previous page Go to next page

4
Visual Information Retrieval Reference

The Visual Information Retrieval library consists of:

The examples in this chapter assume that a table called stockphotos has been created and filled with some photographic images. The table was created using the following SQL statement:

CREATE TABLE stockphotos (photo_id NUMBER, photographer VARCHAR2(64),
             annotation VARCHAR2(255), photo ORDSYS.ORDVIR);

When you are storing or copying images, you must first create an empty BLOB in the table. The following method invocation creates an empty Visual Information Retrieval object:

ORDSYS.ORDVIR.init();

Methods invoked at the ORDSource level that are handed off to the source plug-in for processing have ctx(RAW(4000)) as their first argument. Before calling any of these methods for the first time, the client must perform the following tasks:

  1. Allocate the ctx structure.

  2. Initialize the ctx structure to null.

  3. Invoke the source.open( ) method.

    At this point, the source plug-in can initialize the context for this client.

  4. When processing is complete, the client should invoke the source.close( ) method.

See Oracle interMedia Audio, Image, and Video User's Guide and Reference for descriptions of source methods.


Note:

If you manipulate the image data itself by either directly modifying the BLOB, or changing the external source, then you must ensure that the object attributes stay synchronized and the update time is modified. Otherwise, the object attributes will not match the image data. 


4.1 Ensuring Future Compatibility with an Evolving ORDVir Object Type

Oracle Corporation may evolve the ORDVir object type by adding new object attributes in a future release of Visual Information Retrieval. Client-side applications that you want to maintain compatibility to the 8.1.7 release of the ORDVir object type even after a server upgrade that evolves the object type are advised to do the following:

4.1.1 When and How to Call the Compatibility Initialization Function

Only client-side applications that statically understand the structure of the ORDVir object type need to make a call to the compatibility initialization function. Server-side stored procedures automatically use the newly installed (potentially evolved) ORDVir object type after an upgrade so you do not need to call the compatibility initialization function from server-side stored procedures.

Client-side applications that do not statically (at compile time) understand the structure of ORDVir object type do not need to call the compatibility initialization function. Oracle Call Interface (OCI) applications that determine the structure of the ORDVir object type at runtime through the OCIDescribeAny call do not need to call the compatibility initialization function.

Client-side applications written in OCI that have been compiled with the C structure of an ORDVir object type (generated by the Object Type Translator (OTT)) should make a call to the server-side PL/SQL function, ORDSYS.VIR.compatibilityInit( ), at the beginning of the application. See the reference description of this function later in this section.

Client-side applications written in Java using the Visual Information Retrieval Java Classes for 8.1.7 should call the OrdMediaUtil.virCompatibilityInit( ) function after connecting to an Oracle database.

public static void virCompatibilityInit(OracleConnection con)
    throws Exception

This Java function takes OracleConnection as an argument. The included Visual Information Retrieval 8.1.7 Java API ensures that your 8.1.7 application will work (without upgrading) with a potential future version of Visual Information Retrieval with an evolved object type.

There is not yet a way for client-side PL/SQL applications to maintain compatibility to the 8.1.7 release of the ORDVir object type if the objects are evolved to add new attributes in a future release.

See the reference description of the compatibilityInit( ) function later in this section and the Oracle Visual Information Retrieval Java Classes User's Guide and Reference, release 8.1.7 for further information along with detailed descriptions and examples. This guide will be available on the Oracle Technology Network at

http://technet.oracle.com/


compatibilityInit( ) Method

Format

compatibilityInit(release IN VARCHAR2,

errmsg OUT VARCHAR2)

RETURN NUMBER;

Description

Allows for compatibly evolving the ORDVir object type in a future release.

Parameters

release

The string input parameter. This string should be set to '8.1.7' to allow an 8.1.7 application to work (without upgrading) with a potential future release of the Oracle database server and Visual Information Retrieval with an evolved ORDVir object type.

errmsg

The string output parameter. If this function returns a status other than 0, this errmsg string contains the reason for the failure.

Pragmas

None.

Exceptions

None.

Usage Notes

You should begin using the compatibilityInit( ) method as soon as possible to ensure that you will not have to upgrade the Oracle software on your client node or recompile your client application to work with a future release of the Oracle database server if the ORDVir object type evolves in a future release. See Section 4.1.1 to determine if you need to call this function.

The compatibility initialization function for Visual Information Retrieval is located in the ORDSYS.VIR package.

Examples

This example uses OCI and sets the compatililityInit( ) method release parameter to release 8.1.7 to allow an 8.1.7 application to work with a future release of Oracle and ORDVir with an evolved object type; note, that this is not a standalone program in that it assumes that you have allocated handles beforehand:

void prepareExecuteStmt( OCIEnv *envHndl,
             OCIStmt **stmtHndl,
             OCIError *errorHndl,
             OCISvcCtx *serviceCtx,
             OCIBind *bindhp[] )
{
   text *statement = (text *)
      "begin :sts := ORDSYS.VIR.compatibilityInit( :vers, :errText );
end;";
  sword sts = 0;
  text *vers = (text *)"8.1.7";
  text errText[512];
  sb2 nullInd;

  printf( " Preparing statement\n" );

  OCIHandleAlloc( envHndl, (void **) stmtHndl, OCI_HTYPE_STMT, 0, NULL
);

  OCIStmtPrepare( *stmtHndl, errorHndl, (text *)statement,
         (ub4)strlen( (char *)statement ), OCI_NTV_SYNTAX,
         OCI_DEFAULT );

  printf( " Executing statement\n" );

  OCIBindByPos( *stmtHndl, &bindhp[ 0 ], errorHndl, 1, (void *)&sts,
        sizeof( sts ), SQLT_INT, (void *)0, NULL, 0, 0,
        NULL, OCI_DEFAULT );

  OCIBindByPos( *stmtHndl, &bindhp[ 1 ], errorHndl, 2, vers,
        strlen((char *)vers) + 1, SQLT_STR, (void *)0, NULL,
        0, 0, NULL, OCI_DEFAULT );

  OCIBindByPos( *stmtHndl, &bindhp[ 2 ], errorHndl, 3, errText,
        sizeof( errText ), SQLT_STR, &nullInd, NULL, 0, 0,
        NULL, OCI_DEFAULT);

  OCIStmtExecute( serviceCtx, *stmtHndl, errorHndl, 1, 0,
        (OCISnapshot *)NULL, (OCISnapshot *)NULL, OCI_DEFAULT );

  printf( " Statement executed\n" );
  if (sts != 0)
    {
    printf( "CompatibilityInit failed with Sts = %d\n", sts );
    printf( "%s\n", errText );
    }


}

4.2 Object Type

The Visual Information Retrieval object type ORDVir is composed of the ORDImage type and a signature attribute. The ORDImage type is composed of the ORDSource type and a number of additional descriptive attributes.

This section presents reference information on the object types.

For more information on BLOBs and BFILEs, see Oracle8i Application Developer's Guide - Large Objects (LOBs). For more information on the ORDImage and ORDSource types, see Oracle interMedia Audio, Image, and Video User's Guide and Reference.


ORDVir Object Type

The ORDVir object type supports storage and retrieval of image data stored in a BLOB, external file, or referenced by a URL. This object type is defined as follows:

CREATE TYPE ORDVIR AS OBJECT
(
-- TYPE ATTRIBUTES
image               ORDImage,
signature           RAW(2000)
-- METHOD DECLARATION
-- CONSTRUCTORS
STATIC FUNCTION init( ) RETURN ORDVir,
STATIC FUNCTION init(srcType     IN VARCHAR2,
                     srcLocation IN VARCHAR2,
                     srcName     IN VARCHAR2) RETURN ORDVir,

 -- IMAGE COPY METHOD
  MEMBER PROCEDURE copy(dest IN OUT NOCOPY ORDVir), 

 -- IMAGE PROCESSING RELATED METHODS
  MEMBER PROCEDURE process(SELF    IN OUT ORDVir,
                           command IN     VARCHAR2),
  MEMBER PROCEDURE processCopy(command IN     VARCHAR2, 
                               dest    IN OUT NOCOPY ORDVir),

 -- IMAGE PROPERTY SET AND CHECK METHODS
  MEMBER PROCEDURE setProperties(SELF IN OUT ORDVir),
  MEMBER PROCEDURE setProperties(SELF IN OUT ORDVir,
                                 description IN VARCHAR2),
  MEMBER FUNCTION checkProperties RETURN BOOLEAN,

   -- IMAGE ATTRIBUTE ACCESSOR METHODS
  MEMBER FUNCTION getHeight RETURN INTEGER,
  PRAGMA RESTRICT_REFERENCES(getHeight, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER FUNCTION getWidth RETURN INTEGER,
  PRAGMA RESTRICT_REFERENCES(getWidth, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER FUNCTION getFileFormat RETURN VARCHAR2,
  PRAGMA RESTRICT_REFERENCES(getFileFormat, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER FUNCTION getContentFormat RETURN VARCHAR2,
  PRAGMA RESTRICT_REFERENCES(getContentFormat, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER FUNCTION getCompressionFormat RETURN VARCHAR2,
  PRAGMA RESTRICT_REFERENCES(getCompressionFormat, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER FUNCTION getSignature RETURN RAW,
  PRAGMA RESTRICT_REFERENCES(getSignature, WNDS, WNPS, RNDS, RNPS),
  -- DATE RELATED METHODS
  MEMBER FUNCTION  getUpdateTime RETURN DATE,
  PRAGMA RESTRICT_REFERENCES(getUpdateTime, WNDS, WNPS, RNDS, RNPS),
  MEMBER PROCEDURE setUpdateTime(current_time DATE),
 
  -- MIMETYPE RELATED METHODS
  MEMBER FUNCTION getMimeType RETURN VARCHAR2,
  PRAGMA RESTRICT_REFERENCES(getMimeType, WNDS, WNPS, RNDS, RNPS),
  MEMBER PROCEDURE setMimeType(mimetype IN VARCHAR),
 
  -- SOURCE/CONTENT RELATED METHODS
  MEMBER FUNCTION  getContentLength RETURN INTEGER,
  PRAGMA RESTRICT_REFERENCES(getContentLength, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER FUNCTION  getContent RETURN BLOB,
  PRAGMA RESTRICT_REFERENCES(getContent, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER FUNCTION  getBFILE RETURN BFILE,
  PRAGMA RESTRICT_REFERENCES(getBFILE, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER PROCEDURE deleteContent,
 
  MEMBER PROCEDURE setSource(source_type     IN VARCHAR2, 
                             source_location IN VARCHAR2, 
                             source_name     IN VARCHAR2),
  MEMBER FUNCTION  getSource RETURN VARCHAR2,
  PRAGMA RESTRICT_REFERENCES(getSource, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER FUNCTION  getSourceType RETURN VARCHAR2,
  PRAGMA RESTRICT_REFERENCES(getSourceType, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER FUNCTION  getSourceLocation RETURN VARCHAR2,
  PRAGMA RESTRICT_REFERENCES(getSourceLocation, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER FUNCTION  getSourceName RETURN VARCHAR2,
  PRAGMA RESTRICT_REFERENCES(getSourceName, WNDS, WNPS, RNDS, RNPS),
 
  MEMBER PROCEDURE import(ctx IN OUT RAW),
  MEMBER PROCEDURE importFrom(ctx IN OUT RAW,
                          source_type IN VARCHAR2,
                          source_location IN VARCHAR2,
                          source_name IN VARCHAR2),
  MEMBER PROCEDURE export(ctx      IN OUT RAW,
                          source_type     IN VARCHAR2,
                          source_location IN VARCHAR2,
                          source_name     IN VARCHAR2),
 
  MEMBER PROCEDURE setLocal,
  MEMBER PROCEDURE clearLocal,
  MEMBER FUNCTION isLocal RETURN BOOLEAN,
  PRAGMA RESTRICT_REFERENCES(isLocal, WNDS, WNPS, RNDS, RNPS),
 
  -- MIGRATION RELATED METHODS
  MEMBER PROCEDURE migrateFromORDVirB(
                        SELF IN OUT ORDVIR,
                        old_object IN ORDVirB),
 
  MEMBER PROCEDURE migrateFromORDVirF(
                        SELF IN OUT ORDVIR,
                        old_object IN ORDVirF),
 
  -- VIRAGE RELATED METHODS
  MEMBER PROCEDURE analyze(SELF IN OUT ORDVir) 
);

The ORDImage object type consists of the fields shown in Table 4-1.


Table 4-1 ORDImage Object Type  
Attribute  Data Type  Description 

source 

ORDSource 

Points to the source of the stored image data 

height 

INTEGER 

Height of the image in pixels 

width 

INTEGER 

Width of the image in pixels 

contentLength 

INTEGER 

Size of the on-disk image file in bytes 

fileFormat 

VARCHAR2(4000) 

File type of image (such as, TIFF or JFIF) 

contentFormat 

VARCHAR2(4000) 

Type of image (such as, monochrome or
8-bit grayscale 

compressionFormat 

VARCHAR2(4000) 

Compression type of the image 

mimeType 

VARCHAR2(4000) 

MIME type of the image 

The ORDSource object type consists of the fields shown in Table 4-2.


Table 4-2 ORDSource Object Type
Attribute  Data Type  Description 

localData 

BLOB 

Locally stored image data. 

srcType 

VARCHAR2(4000) 

Identifies the source type as one of the
following:

  • NULL

  • 'FILE' -- source is an external file

  • 'HTTP' -- HTTP server name

  • '<name>' -- name of another source

 

srcLocation 

VARCHAR2(4000) 

Identifies where the data can be found based on the srcType.
See Table 4-3.  

srcName 

VARCHAR2(4000) 

Identifies the data object name based on the source type.
See Table 4-4

updateTime 

DATE 

The time at which the data was last updated. 

local 

NUMBER 

Flag to determine if the data is local (1) or not (0). 

Table 4-3 describes the valid srcLocation values.


Table 4-3 srcLocation Values  
srcType  srcLocation 

NULL 

NULL or not accessed 

FILE 

<DIR> or name of the directory object 

HTTP 

<SourceBase> or URL needed to find the base directory 

<name> 

<iden> or identifier string required to access another server 

Table 4-4 describes the valid srcName values.


Table 4-4 Valid srcName Values 
srcType  srcName 

NULL 

NULL or not accessed 

FILE 

<FILE> or name of the file 

HTTP 

<Source> or name of the object 

<name> 

<object name> or name of the object 

In PL/SQL, data is moved with the DBMS LOB package. From the client, data is moved using OCI LOB calls. The ORDVir object type does not supply routines for moving data piece by piece.

4.3 Constructors

This section describes the constructor functions.

The Visual Information Retrieval constructor functions are as follows:


init( ) Method

Format

init( ) RETURN ORDVir;

Description

Allows for easy initialization of instances of the ORDVir object type.

Parameters

None.

Pragmas

None.

Exceptions

None.

Usage Notes

This static method initializes all the ORDVir attributes to NULL with the following exceptions:

You should begin using the init( ) method as soon as possible to allow you to more easily initialize the ORDVir object type, especially if the ORDVir type evolves and attributes are added in a future release. INSERT statements left unchanged using the default constructor, (which initializes each object attribute) will fail under these circumstances.

Examples

Initialize the ORDVir object attributes:

DECLARE
  myImage ORDSYS.ORDVir;
BEGIN
  myImage := ORDSYS.ORDVir.init( );
INSERT INTO stockphotos VALUES (myImage);
END;
/

init( ) Method

Format

init(srcType IN VARCHAR2,

srcLocation IN VARCHAR2,

srcName IN VARCHAR2)

RETURN ORDVir;

Description

Allows for easy initialization of instances of the ORDVir object type.

Parameters

srcType

The source type of the image data.

srcLocation

The source location of the image data.

srcName

The source name of the image data.

Pragmas

None.

Exceptions

None.

Usage Notes

This static method initializes all the ORDVir attributes to NULL with the following exceptions:

You should begin using the init( ) method as soon as possible to allow you to more easily initialize the ORDVir object type, especially if the ORDVir type evolves and attributes are added in a future release. INSERT statements left unchanged using the default constructor, (which initializes each object attribute) will fail under these circumstances.

Examples

Initialize the ORDVir object attributes:

DECLARE
  myImage ORDSYS.ORDVir;
BEGIN
  myImage := ORDSYS.ORDVir.init('FILE','VIRDIR','image1.gif');
INSERT INTO stockphotos VALUES (myImage);
END;
/


















4.4 Methods for Image Manipulation

This section presents reference information on the methods used for image manipulation.

The Visual Information Retrieval methods are as follows:

For more information on object types and methods, see Oracle8i Concepts.

Note that some of the following methods have pragmas, or compiler directives, associated with them. The pragma tells the PL/SQL compiler what sort of access the method needs to the database. The compiler can then deny the method read/write access to database tables, packaged variables, or both. Methods with defined pragma (such as the getXXX methods) can be called from SQL expressions.

Pragmas use the following syntax:

PRAGMA RESTRICT REFERENCES (function_name, WNDS, [,WNPS] [,RNDS] [RNPS]);

where:


analyze( ) Method

Format

analyze( );

Description

Analyzes an image, derives information relating to the visual attributes, and creates the image signature.

Parameters

None.

Pragmas

None.

Exceptions

None.

Usage Notes

The analyze( ) method creates the image attribute signature, which is necessary for any content-based retrieval. Whenever you are working with a new or changed image, you should also use the SetProperties( ) method to set the other image characteristics.

The analyze( ) method is functionally equivalent to the Analyze( ) operator. You must use the analyze( ) method, and not the operator, when working with foreign images (images not natively supported).

Examples

Create the signatures for all images in the stockphotos table.

DECLARE
   temp_image   ORDSYS.ORDVir;
   temp_id      INTEGER;
   cursor c1 is select id, image from stockphotos for update;
BEGIN
   OPEN c1;
   LOOP
      fetch c1 into temp_id, temp_image;
      EXIT WHEN c1%NOTFOUND;
  
 -- Generate signature and set the properties for the image.
      temp_image.analyze; 
      temp_image.setProperties;
      UPDATE stockphotos SET photo = temp_image WHERE photo_id = temp_id;
   END LOOP;
   CLOSE c1;
END;


checkProperties( ) Method

Format

checkProperties RETURN BOOLEAN;

Description

Verifies that the properties stored in attributes of the image object match the properties of the image. This method should not be used for foreign images.

Parameters

None.

Pragmas

None.

Exceptions

None.

Usage Notes

Use this method to verify that the image attributes match the actual image.

Examples

Check the image attributes.

image            ORDSYS.ORDVir;
properties_match BOOLEAN;
BEGIN
  SELECT photo INTO image FROM stockphotos
    WHERE photo_id=1 FOR UPDATE;
  properties_match := image.checkProperties;
  IF properties_match THEN DBMS_OUTPUT.PUT_LINE('Check Properties Succeeded');
  END IF;
END;

clearLocal( ) Method

Format

clearLocal;

Description

Resets the local flag value from local (1) to nonlocal (0) for the source of the data.

Parameters

None.

Pragmas

None.

Exceptions

None.

Usage Notes

When the local flag is clear (0), this means that the data is stored externally. In that case, Visual Information Retrieval methods look for image data in the srcType, srcName, and srcLocation attributes.

Examples

Reset the local flag.

DECLARE
    Image ORDSYS.ORDVir;
BEGIN
    SELECT photo INTO Image FROM stockphotos WHERE photo_id = 1 FOR UPDATE;
 
    -- clear local so we look for image externally
    Image.clearLocal;
  
    UPDATE stockphotos SET photo = Image WHERE photo_id = 1;
END;
/

copy( ) Method

Format

copy(dest IN OUT NOCOPY ORDVir);

Description

Copies an image without changing it.

Parameters

dest

The destination of the new image.

Pragmas

None.

Exceptions

NULL_LOCAL_DATA -- Raised if the destination source.localData is not initialized, or if the source.isLocal value is 1 and source.localData is NULL.

Usage Notes

This method copies the image data, as is, including all source and image attributes, into the supplied local destination image.

If the data is stored locally in the source, then calling this method copies the BLOB to the destination source.localData field.

Calling this method copies the external source information to the external source information of the new image, whether or not the source data is stored locally.

Calling this method implicitly calls the setUpdateTime method on the destination object to update its timestamp information.

Examples

Create a copy of the image.


DECLARE
    Image_1 ORDSYS.ORDVir;
    Image_2 ORDSYS.ORDVir;
BEGIN
    SELECT photo,
       INTO Image_2
       FROM stockphotos
       WHERE photo_id = 1 FOR UPDATE;
    SELECT photo,
       INTO Image_1
       FROM stockphotos
       WHERE photo_id = 1;

    -- copy the data from Image_1 to Image_2
    Image_1.copy(Image_2);
    UPDATE stockphotos SET photo = Image_2
        WHERE photo_id = 2;
END;

deleteContent Method

Format

deleteContent;

Description

Deletes the local data from the current local source (localData).

Parameters

None.

Pragmas

None.

Exceptions

None.

Usage Notes

This method can be called after you export the data from the local source to an external image data source and you no longer need this data in the local source.

Examples

Delete the local data from the current local source.

DECLARE
    Image ORDSYS.ORDVir;
BEGIN
    SELECT photo INTO Image FROM stockphotos
      WHERE photo_id = 1 FOR UPDATE;
     -- delete the local content of the image
    Image.deleteContent;
    UPDATE stockphotos SET photo = Image WHERE photo_id = 1;
END;
/

export( ) Method

Format

export(ctx IN OUT RAW,

source_type IN VARCHAR2,

source_location IN VARCHAR2,

source_name IN VARCHAR2);

Description

Transfers image data from a local source (localData) within an Oracle database to an external image data source.

Parameters

ctx

The source plug-in context information.

source_type

The source type of the location where the image data is to be exported.

source_location

The location where the image data is to be exported.

source_name

The name of the image object where the image is to be exported.

Pragmas

None.

Exceptions

None.

Usage Notes

After exporting image data, all image attributes remain unchanged and srcType, srcLocation, and srcName are updated with input values. After calling the export method, you can call the clearLocal( ) method to indicate the data is stored outside the database and call the deleteContent method if you want to delete the content of the local data.

This method is available for user-defined sources that can support the export method.

The only server-side native support for the export method is for the srcType 'FILE'.

The export( ) method for a source type of 'FILE' is similar to a file copy operation in that the original data stored in the BLOB is not touched other than for reading purposes.

The export( ) method is not an exact mirror operation to the import( ) method in that the clearLocal( ) method is not automatically called to indicate the data is stored oudside the database, whereas the import( ) method automatically calls the setLocal( ) method.

Call the deleteContent method after calling the export( ) method to delete the content from the database if you no longer intend to manage the multimedia data within the database.

The export( ) method only writes to a directory object that the user has privileges to access. That is, you can access a directory that you created using the SQL CREATE DIRECTORY statement or one to which you were granted READ access. To execute the CREATE DIRECTORY statement, you must have the CREATE ANY DIRECTORY privilege. In addition, you must use the DBMS_JAVA.GRANT_PERMISSION call to specify which files can be written.

For example, the following grants the user, MEDIAUSER, the right to write to the file named filename.dat.

CALL DBMS_JAVA.GRANT_PERMISSION(
        'MEDIAUSER',
        'java.io.FilePermission',
        '/actual/server/directory/path/filename.dat',
        'write');

See the security and performance section in the Oracle8i Java Developer's Guide for more information.

Whenever you import or export images with signature data between platforms, you should use the convert( ) method to ensure that the signature is in the correct format.

Invoking this method implicitly calls the setUpdateTime( ) method.

Examples

Export image data to an external data source, reset the local attribute, and delete the local content.

DECLARE
  myImage ORDSYS.ORDVir;
  ctx RAW(4000) := NULL;
BEGIN
  SELECT photo INTO myImage FROM stockphotos WHERE photo_id=1; 
  myImage.export(ctx,'FILE','IMAGEDIR','image1.gif';
  myImage.clearLocal;
  myImage.deleteContent;
END;
/

getBFILE Method

Format

getBFILE RETURN BFILE;

Description

Returns the LOB locator of the BFILE containing the image.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getBFILE, WNDS, WNPS, RNDS, RNPS)

Exceptions

INCOMPLETE_SOURCE_INFORMATION -- Raised if the srcType is NULL.

INVALID_SOURCE_TYPE -- Raised if srcType is not FILE.

Usage Notes

This method constructs a BFILE using the stored srcLocation and srcName. srcLocation must contain a defined directory object, and srcName must contain a valid file name.

Examples

Get the BFILE for the image.

DECLARE
    Image ORDSYS.ORDVir;
    imagebfile BFILE;
BEGIN
    SELECT photo INTO Image FROM stockphotos
      WHERE photo_id = 1;
 
    -- get the image BFILE
    imagebfile := Image.getBFILE;
END;

getCompressionFormat Method

Format

getCompressionFormat RETURN VARCHAR2;

Description

Returns the compression type of an image. This method does not actually read the image, it is a simple accessor method that returns the value of the compressionFormat attribute.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getCompressionFormat, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

Use this method rather than accessing the compressionFormat attribute directly to protect yourself from potential changes to the internal representation of the ORDVir object.

Examples

Get the compression type of an image.

imgb1             ORDSYS.ORDVir;
compressionFormat VARCHAR2(4000);

...
compressionFormat := imgb1.getCompressionFormat;


getContent Method

Format

getContent RETURN BLOB;

Description

Returns the LOB locator of the BLOB containing the image. This is a simple access method that returns the value of the localData attribute.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getContent, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

This method can be used in conjunction with the getMimeType method. For example, a client trying to access image data to put it on a Web-based viewer can call getMimeType and publish the header and then call getContent to access the image data and send it over the wire.

Use this method rather than accessing the content attribute directly, to protect yourself from potential changes to the internal representation of the ORDVir object.

Examples

A client accesses image data.

DECLARE
    Image ORDSYS.ORDVir;
    localData BLOB;
BEGIN
    SELECT photo INTO Image FROM stockphotos
      WHERE photo_id = 1;
    -- get the image BLOB
    localData := Image.getContent;
END;

getContentFormat Method

Format

getContentFormat RETURN VARCHAR2;

Description

Returns the format of an image (such as monochrome or 8-bit grayscale). This method does not actually read the image; it is a simple access method that returns the value of the contentFormat attribute.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getContentFormat, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

Use this method rather than accessing the contentFormat attribute directly to protect yourself from potential changes to the internal representation of the ORDVir object.

Examples

Get the type of an image.

imgb1         ORDSYS.ORDVir;
contentFormat VARCHAR2(4000);

...
contentFormat := imgb1.getContentFormat;

getContentLength( ) Method

Format

getContentLength RETURN INTEGER;

Description

Returns the length of the image data content stored in the source. This method does not actually read the image; it is a simple access method that returns the value of the contentLength attribute.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getContentLength, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

Use this method rather than accessing the contentLength attribute directly to protect yourself from potential changes to the internal representation of the ORDVir object.

Examples

Get the length of the image data content stored in the source.

imgb1         ORDSYS.ORDVir;
contentLength INTEGER;

...
contentLength := imgb1.getContentLength;

getFileFormat( ) Method

Format

getFileFormat RETURN VARCHAR2;

Description

Returns the file type of an image (such as TIFF or JFIF). This method does not actually read the image; it is a simple access method that returns the value of the fileFormat attribute.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getFileFormat, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

Use this method rather than accessing the fileFormat attribute directly to protect yourself from potential changes to the internal representation of the ORDVir object.

Examples

Get the file type of an image.

imgb1      ORDSYS.ORDVir;
fileFormat VARCHAR2(4000);

...
fileFormat := imgb1.getFileFormat;


getHeight( ) Method

Format

getHeight RETURN INTEGER;

Description

Returns the height of an image in pixels. This method does not actually read the image; it is a simple accessor method that returns the value of the height attribute.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getHeight, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

Use this method rather than accessing the height attribute directly to protect yourself from potential changes to the internal representation of the ORDVir object.

Examples

Get the height of an image.

imgb1  ORDSYS.ORDVir;
height INTEGER;

...
height := imgb1.getHeight;

getMimeType( ) Method

Format

getMimeType RETURN VARCHAR2;

Description

Returns the MIME (Multipurpose Internet Mail Exchange) type of an image (such as image/jpeg or image/gif). This method does not actually read the image; it is a simple access method that returns the value of the mimeType attribute.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getMimeType, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

Use this method to obtain the MIME type of the image. The MIME type is required by Web browsers along with image content. It tells the Web browser how to interpret the image.

For unrecognizable formats, you must call the setMimeType( ) method and specify the appropriate MIME type.

See Appendix A for the MIME type associated with each supported file type.

Examples

Return the MIME media type.

imgb1      ORDSYS.ORDVir;
mimeType   VARCHAR2(4000);
...
mimeType := imgb1.getMimeType;

getSignature( ) Method

Format

getSignature RETURN RAW;

Description

Returns the signature of an image. This method does not actually create the image signature; it is a simple access method that returns the contents of the signature attribute.

Parameters

None.

Pragmas

None.

Exceptions

None.

Usage Notes

Use this method rather than accessing the signature attribute directly to protect yourself from potential changes to the internal representation of the ORDVir object.

Examples

Get the signature of an image.

virb1     ORDSYS.ORDVir;
signature RAW(2000);

...
signature := virb1.getSignature;


getSource( ) Method

Format

getSource RETURN VARCHAR2;

Description

Returns information about the external location of the image data in URL format.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getSource, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

The possible return values for this method are:

Examples

Get the source of the image data.

DECLARE
    Image ORDSYS.ORDVir;
    SourceInfo VARCHAR2(4000);
BEGIN
    SELECT photo INTO Image FROM stockphotos
      WHERE photo_id = 1;
    -- get the image source information
    SourceInfo := Image.getSource;
END;

getSourceLocation( ) Method

Format

getSourceLocation RETURN VARCHAR2;

Description

Returns a formatted string containing the external image data source location.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getSourceLocation, WNDS, WNPS, RNDS, RNPS)

Exceptions

INCOMPLETE_SOURCE_LOCATION -- Raised if the location is not set in the image object.

Usage Notes

This method returns a VARCHAR2 string formatted as <location> for the current value of the srcLocation attribute.

Examples

Get the source information about an image data source location.

DECLARE
    Image ORDSYS.ORDVir;
    SourceLocation VARCHAR2(4000);
BEGIN
    SELECT photo INTO Image FROM stockphotos
      WHERE photo_id = 1;
 
    -- get the image source location
    SourceLocation := Image.getSourceLocation;
END;

getSourceName( ) Method

Format

getSourceName RETURN VARCHAR2;

Description

Returns a string containing the name of the external image data source.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getSourceName, WNDS, WNPS, RNDS, RNPS)

Exceptions

INCOMPLETE_SOURCE_NAME -- Raised if the srcName is not set in the image object.

Usage Notes

This method returns a VARCHAR2 string containing the name of the external data source, for example, 'testimg.dat'.

Examples

Get the source name information about an image data source.

DECLARE
    Image ORDSYS.ORDVir;
    SourceName VARCHAR2(4000);
BEGIN
    SELECT photo INTO Image FROM stockphotos
      WHERE photo_id = 1;
 
    -- get the image source name
    SourceName := Image.getSourceName;
END;
/

getSourceType( ) Method

Format

getSourceType RETURN VARCHAR2;

Description

Returns a string containing the type of the external data source.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getSourceType, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

This method returns a VARCHAR2 string containing the type of the external image data source, for example, 'FILE'.

Examples

Get the source type information about an image data source.

DECLARE
    Image ORDSYS.ORDVir;
    SourceType VARCHAR2(4000);
BEGIN
    SELECT photo INTO Image FROM stockphotos
      WHERE photo_id = 1;
 
    -- get the image source type
    SourceType := Image.getSourceType;
END;
/

getUpdateTime( ) Method

Format

getUpdateTime RETURN DATE;

Description

Returns the time when the image was last updated.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getUpdateTime, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

None.

Examples

Get the updated time of some image data.

DECLARE
   Image       ORDSYS.ORDVir;
   UpdateTime  DATE;
BEGIN
   SELECT photo INTO Image FROM stockphotos
     WHERE photo_id = 1;
 -- get the image update time
   UpdateTime := Image.getUpdateTime;
END;
/

getWidth( ) Method

Format

getWidth RETURN INTEGER;

Description

Returns the width of an image in pixels. This method does not actually read the image; it is a simple access method that returns the value of the width attribute.

Parameters

None.

Pragmas

PRAGMA RESTRICT_REFERENCES(getWidth, WNDS, WNPS, RNDS, RNPS)

Exceptions

None.

Usage Notes

Use this method rather than accessing the width attribute directly to protect yourself from potential changes to the internal representation of the ORDVir object.

Examples

Get the width of an image.

imgb1  ORDSYS.ORDVir;
width  INTEGER;

...
width := imgb1.getWidth;

import( ) Method

Format

import(ctx IN OUT RAW);

Description

Transfers image data from an external image data source to a local source (localData) within an Oracle database.

Parameters

ctx

Specifies the source plug-in context information. The ctx structure must be allocated, and you must call the source.open( ) method. See the beginning of this chapter for more information.

Pragmas

None.

Exceptions

Usage Notes

Use the setSource( ) method to set the external source type, location, and name, before calling the import( ) method.

After importing data from an external image data source to a local source (within an Oracle database), the source information remains unchanged (that is, it points to the source from where the data was imported).

Invoking this method implicitly calls the setUpdateTime( ) and setLocal methods.

If the file format of the imported image is not previously set to a string beginning with "OTHER", the setProperties( ) method is also called. Set the file format to a string preceded by "OTHER" for foreign image formats; calling the setProperties( ) method for Foreign Images does this for you.

Whenever you import or export images with signature data between platforms, you should use the convert( ) method to ensure that the signature is in the correct format.

Examples

Import image data from an external image data source into the local source.

DECLARE
    Image ORDSYS.ORDVir;
    ctx  RAW(4000) := NULL;
BEGIN
    -- select the image to be imported
    SELECT photo INTO Image FROM stockphotos
           WHERE photo_id = 1 FOR UPDATE;
    
    -- import the image into the database
    Image.import(ctx);
END;
/


importFrom( ) Method

Format

importFrom(ctx IN OUT RAW,

source_type IN VARCHAR2,

source_location IN VARCHAR2,

source_name IN VARCHAR2);

Description

Transfers image data from the specified external image data source to a local source (localData) within an Oracle database.

Parameters

ctx

Specifies the source plug-in context information. The ctx structure must be allocated, and you must call the source.open( ) method. See the beginning of this chapter for more information.

source_type

Specifies the source type of the image data.

source_location

Specifies the location from which the image data is to be imported.

source_name

Specifies the name of the image data.

Pragmas

None.

Exceptions

None.

Usage Notes

This method is similar to the import( ) method, except the source information is specified as parameters to the method instead of separately.

After importing data from an external image data source to a local source (within an Oracle database), the source information remains (set to the input parameters) and points to the source from where the data was imported.

Invoking this method implicitly calls the setUpdateTime( ) and setLocal methods.

If the file format of the imported image is not previously set to a string beginning with OTHER, the setProperties( ) method is also called. Set the file format to a string preceded by OTHER for foreign image formats; calling the setProperties( ) method for Foreign Images does this for you.

Whenever you import or export images with signature data between platforms, you should use the convert( ) method to ensure that the signature is in the correct format.

Examples

Import image data from the specified external data source into the local source.

DECLARE
    Image ORDSYS.ORDVir;
    ctx   RAW(4000):=NULL;
BEGIN
    -- select the image to be imported
    SELECT photo INTO Image FROM stockphotos
           WHERE photo_id = 1 FOR UPDATE;
    
    -- import the image into the database
    Image.importFrom(ctx,
                     'FILE',
                     'ORDVIRDIR',
                     'virdemo1.dat');
 
    UPDATE stockphotos SET photo = Image WHERE photo_id = 1;
END;
/



isLocal( ) Method

Format

isLocal RETURN BOOLEAN;

Description

Returns the current value of the local flag, indicating whether or not the data is stored locally.

Parameters

None.

Pragmas

Pragma RESTRICT_REFERENCES(isLocal, WNDS, WNPS,RNDS,RNPS)

Exceptions

None.

Usage Notes

A value of TRUE means the data is local to the database. A value of FALSE means the data is external to the database.

Examples

Determine whether or not data is local.

DECLARE
    Image ORDSYS.ORDVir;
BEGIN
    SELECT photo INTO Image FROM stockphotos WHERE photo_id = 1; 
    -- check to see if image is stored locally
    IF Image.isLocal THEN
        DBMS_OUTPUT.PUT_LINE('Image is stored locally');
    ELSE
        DBMS_OUTPUT.PUT_LINE('Image is stored externally');
    END IF;
END;


migrateFromORDVirB( ) Method

Format

migrateFromORDVirB(old_object ORDVirB);

Description

Allows you to migrate old ORDVirB images to the new ORDVir object type.

Parameters

old_object

The old ORDVirB image.

Pragmas

None.

Exceptions

Usage Notes

This method copies images from the source BLOB to the destination BLOB, copies all image attributes from the old object to the new object, and sets the update time and local attribute.

Examples

Migrate an old ORDVirB image to a new ORDVir image.

DECLARE
    Image ORDSYS.ORDVir;
    old_image ORDSYS.ORDVirB;
BEGIN
    -- Select the old image
    SELECT imageb INTO old_image FROM old_images WHERE id = 1;
 
    -- Select the new image
    SELECT photo INTO Image FROM stockphotos WHERE photo_id = 1 FOR UPDATE;
 
    -- Migrate from the old to the new
    Image.migrateFromORDVirB(old_image);
 
    UPDATE stockphotos SET photo = Image WHERE photo_id = 1;
END;
/


migrateFromORDVirF( ) Method

Format

migrateFromORDVirF(old_object ORDVirF);

Description

Allows you to migrate old ORDVirF images to the new ORDVir object type.

Parameters

old_object

The old ORDVirF image.

Pragmas

None.

Exceptions

None.

Usage Notes

Extracts the directory name and file name from the source image and copies them to the srcLocation and SrcName attributes of the destination image. This method copies all image attributes from the old object to the new object, sets the update time, and clears the local attribute.

Examples

Migrate an old ORDVirF image to a new ORDVir image.


DECLARE
    Image ORDSYS.ORDVir;
    old_image ORDSYS.ORDVirF;
BEGIN
    -- Select the old image
    SELECT imagef INTO old_image FROM old_images WHERE id = 1;
 
    -- Select the new image
    SELECT photo INTO Image FROM stockphotos WHERE photo_id = 1 FOR UPDATE;
 
    -- Migrate from the old to the new
    Image.migrateFromORDVirF(old_image);
 
    UPDATE stockphotos SET photo = Image WHERE photo_id = 1;
END;
/


process( ) Method

Format

process(command IN VARCHAR2);

Description

Performs one or more image processing techniques on a BLOB, writing the image back onto itself.

Parameters

command

A list of image processing changes to make for the image.

Pragmas

None.

Exceptions

DATA_NOT_LOCAL -- Raised if data is not local or source.localData is NULL.

Usage Notes

You can change one or more of the image attributes shown in Table 4-5. Table 4-6 shows additional changes that can be made only to raw pixel and foreign images.


Table 4-5 Image Processing Operators  
Operator Name  Usage  Values 

compressionFormat 

Compression type/format 

JPEG, SUNRLE, BMPRLE, TARGARLE, LZW, LZWHDIFF, FAX3, FAX4, HUFFMAN3, Packbits, GIFLZW 

compressionQuality 

Compression quality 

MAXCOMPRATIO, MAXINTEGRITY, LOWCOMP, MEDCOMP, HIGHCOMP 

contentFormat 

Imagetype/pixel/data format 

MONOCHROME, 8BITGRAYSCALE, 8BITGREYSCALE, 8BITLUT, 24BITRGB 

cut 

Window to cut or crop (origin.x origin.y width height) 

(INTEGER INTEGER INTEGER INTEGER) Maximum value is 65535 

fileFormat 

File format of the image 

BMPF, CALS, GIFF, JFIF, PICT, RASF, RPIX, TGAF, TIFF 

fixedScale 

Scale to a specific size in pixels (Width, Height) 

(INTEGER INTEGER) 

maxScale 

Scale to a specific size in pixels, while maintaining the aspect ratio (maxWidth, maxHeight) 

(INTEGER INTEGER) 

scale 

Scale factor (for example, 0.5 or 2.0) 

<FLOAT> positive 

xScale 

X-axis scale factor (Default is 1.) 

<FLOAT> positive 

yScale 

Y-axis scale factor (Default is 1.) 

<FLOAT> positive 

Table 4-6 Additional Image Processing Operators for Raw Pixel and Foreign Images 
Operator Name  Usage  Values 

ChannelOrder 

Indicates the relative position of the red, green, and blue channels (bands) within the image. 

RGB (default), RBG, GRB, GBR, BRG, BGR 

InputChannels 

For multiband images, specify either one (grayscale) or three integers indicating which channels to assign to red (first), green (second), and blue (third). Note that this parameter affects the source image, not the destination. 

INTEGER or
INTEGER INTEGER INTEGER 

Interleave 

Controls band layout within the image:
Band Interleaved by Pixel
Band Interleaved by Line
Band Sequential 

BIP (default), BIL, BSQ 

PixelOrder 

If NORMAL, then the leftmost pixel appears first in the image. 

NORMAL (default), REVERSE 

ScanlineOrder 

If NORMAL, then the top scanline appears first in the image. 

NORMAL (default), INVERSE 


Note:

When specifying values that include floating-point numbers, you must use double quotation marks ("") around the value. If you do not, this may result in incorrect values being passed, and you will get incorrect results. 


There is no implicit import( ) or importFrom( ) call performed when you call this method; if data is external, you must first call import( ) or importFrom( ) to make the data local before you can process it.

Implicit setProperties( ), setUpdateTime( ), and setMimeType( ) methods are performed after the process( ) method is called.

Note that because you are changing the object, you must have the appropriate write access to the table. Also, you must select the object for update.

See Appendix C for complete descriptions of the process( ) operators.

Examples

Example 1: Change the file format of image1 to GIF.

SELECT photo INTO image1 FROM stockphotos where photo_id = 1 FOR UPDATE
image1.process('fileFormat=GIFF');

Example 2: Change image1 to use lower quality JPEG compression and double the length of the image along the x-axis.

image1.process('compressionFormat=JPEG, compressionQuality=LOWCOMP, 
xScale="2.0"'); 

Note that changing the length on only one axis (for example, xScale=2.0) does not affect the length on the other axis, and would result in image distortion. Also, only the xScale and yScale parameters can be combined in a single operation. Any other combinations of scaling operators result in an error.

Example 3: The maxScale and fixedScale operators are especially useful for creating thumbnail images for use on a Web site from various-sized originals. The following line creates a 32-by-32 pixel thumbnail image, preserving the original aspect ratio.

image1.process('maxScale= 32 32');


processCopy( ) Method

Format

processCopy(command IN VARCHAR2,

dest IN OUT NOCOPY ORDVir);

Description

Copies an image stored internally or externally to another image stored internally as a BLOB.

Parameters

command

A list of image processing changes to make for the image in the new copy.

dest

The destination of the new image.

Pragma

None.

Exceptions

NULL_DESTINATION -- Raised if the value of dest is NULL.

NULL_LOCAL_DATA -- Raised if source.localData is NULL and source.isLocal is 1. Also raised if dest.source.localData is NULL.

DATA_NOT_LOCAL -- Raised if the destination image is not local.

Usage Notes

Examples

Copy an image, changing the file format, compression format, and data format in the destination image.

create or replace procedure copyit is 
  imgB1     ORDSYS.ORDVir; 
  imgB4     ORDSYS.ORDVir; 
  mycommand   VARCHAR2(400); 
begin 
  select photo into imgB1 from stockphotos  where photo_id = 1; 
  select photo into imgB4 from stockphotos where photo_id = 4 for update; 
  mycommand:= 'fileFormat=tiff compressionFormat = packbits 
  contentFormat = 8bitlut'; 
  imgB1.processcopy(mycommand,imgB4); 
  update stockphotos set photo = imgB4 where photo_id = 4;
end; 


setLocal Method

Format

setLocal;

Description

Sets the local attribute to indicate that the data is stored internally in a BLOB. When local is set, image methods look for image data in the source.localData attribute.

Parameters

None.

Pragmas

None.

Exceptions

NULL_LOCAL_DATA -- Raised if source.localData is NULL.

Usage Notes

This method sets the local attribute to 1, meaning the data is stored locally in localData.

Examples

Indicate that the image is stored locally.

DECLARE
    Image ORDSYS.ORDVir;
BEGIN
    SELECT photo INTO Image FROM stockphotos WHERE photo_id = 1 FOR UPDATE;
 
    -- set local so we look for the image in the database
    Image.setLocal;
  
    UPDATE stockphotos SET photo = Image WHERE photo_id = 1;
END;
/

setMimeType( ) Method

Format

setMimeType(mime IN VARCHAR2);

Description

Allows you to set the MIME media type of the stored image data.

Parameters

mime

The MIME media type.

Pragmas

None.

Exceptions

None.

Usage Notes

You can override the automatic setting of MIME information by calling this method with a specified MIME value.

Visual Information Retrieval cannot automatically set the MIME type of foreign images. You must use this method to set the MIME type for foreign images.

Examples

Set the MIME media type for some stored image data.

DECLARE
    Image ORDSYS.ORDVir;
BEGIN
    SELECT photo INTO Image FROM stockphotos FOR UPDATE
      WHERE photo_id = 1;
     -- set the image mime type
    Image.setMimeType('image/bmp');
END;

setProperties( ) Method

Format

setProperties;

Description

Reads the image data to get the values of the object attributes, then stores them in the appropriate attribute fields. The image data can be stored in the database in a BLOB, or externally in a BFILE or URL. If the data is stored externally in anything other than a BFILE, the data is read into a temporary BLOB to determine image characteristics.

This method should not be called for foreign images. Use the setProperties(description) method for foreign images.

Parameters

None.

Pragmas

None.

Exceptions

NULL_LOCAL_DATA -- Raised if the source.localData attribute is NULL and the source.local attribute indicates the data is local.

Usage Notes

After you have copied, stored, or processed a native format image, call this method to set the current characteristics of the new content. Note that some methods already call setProperties( ) implicitly.

This procedure sets the following information about an image:

This method implicitly sets the update time and MIME type.

Examples

Select the image, and then set the attributes using the setProperties method.

DECLARE

imgB1 ORDSYS.ORDVir;
BEGIN
select photo into imgB1 from stockphotos where photo_id = 1 for update;
imgB1.setProperties;
dbms_output.put_line('image width = '|| imgB1.getWidth );
dbms_output.put_line('image height = '|| imgB1.getHeight );
dbms_output.put_line('image size = '|| imgB1.getContentLength );
dbms_output.put_line('image file type = '|| imgB1.getFileFormat );
dbms_output.put_line('image type = '|| imgB1.getContentFormat );
dbms_output.put_line('image compression = '|| imgB1.getCompressionFormat )
dbms_output.put_line('image MIME type = '|| imgB1.getMimeType );
END; /

Example output:

image width = 360
image height = 490
image size = 59650
image file type = JFIF
image type = 24BITRGB
image compression = JPEG
image MIME type = image/jpeg

setProperties( ) Method for Foreign Images

Format

setProperties(description IN VARCHAR2);

Description

Allows you to write the characteristics of a foreign image (one not natively supported) into the appropriate attribute fields.

Parameters

description

The image characteristics to set for the foreign image.

Pragmas

None.

Exceptions

NULL_PROPERTIES_DESCRIPTION -- Raised if the description is NULL.

Usage Notes


Note:

Once you have set the properties for a foreign image, it is up to you to keep the properties consistent. If Visual Information Retrieval detects an unknown file format, it will not implicitly set the properties.  


After you copied, stored, or processed a foreign image, call this method to set the characteristics of the new image content. Unlike the native image types described in Appendix A, foreign images either do not contain information on how to interpret the bits in the file or Visual Information Retrieval does not understand the information. In this case, you must set the information explicitly.

You can set the following image characteristics for foreign images, as shown in Table 4-7.


Table 4-7 Image Characteristics for Foreign Images 
Field  Data Type  Description 

CompressionFormat 

STRING 

Value must be CCITG3, CCITG4, or NONE (default). 

DataOffset 

INTEGER 

The offset allows the image to have a header that Visual Information Retrieval does not try to interpret. Set the offset to avoid any potential header. The value must be a positive integer less than the LOB length.
Default is zero. 

DefaultChannelSelection 

INTEGER 

For multiband images, specify either one (grayscale) or three integers indicating which channels to assign to red (first), green (second), and blue (third). For example, DefaultChannelSelection = 1 for single band images and DefaultChannelSelection = 1, 2, 3 for triple-band images. 

Height 

INTEGER 

Height of the image in pixels. Value must be a positive integer. There is no default, and a value must be specified. 

Interleaving 

STRING 

Band layout within the image. Valid styles are:

  • BIP (default): Band Interleaved by Pixel

  • BIL: Band Interleaved by Line

  • BSQ: Band Sequential

 

NumberOfBands 

INTEGER 

Value must be a positive integer less than 255 describing the number of color bands in the image.
Default is 3. 

PixelOrder 

STRING 

If NORMAL (default), the leftmost pixel appears first in the file. If REVERSE, the rightmost pixel appears first. 

ScanlineOrder 

STRING 

If NORMAL (default), the top scanline appears first in the file. If INVERSE, then the bottom scanline appears first. 

UserString 

STRING 

A 4-character descriptive string. If used, the string is stored in the fileFormat field, appended to the file format (OTHER:). Default is blank and fileFormat is set to OTHER. 

Width 

INTEGER 

Width of the image in pixels. Value must be a positive integer. There is no default, and a value must be specified. 

MimeType 

STRING 

Value must be a MIME type, such as img/gif. 

The values supplied to setProperties( ) are written to the existing ORDVir data attributes. The fileFormat is set to OTHER and includes the user string, if supplied, for example, OTHER: DICOM.

Examples

Select the foreign image and then set the properties for the image.

DECLARE
    Image ORDSYS.ORDVIR;
BEGIN
    SELECT photo INTO Image FROM stockphotos
           WHERE photo_id = 1 FOR UPDATE;
    -- set property attributes for the image data
    Image.setProperties('width=123 height=321 compressionFormat=NONE' ||
                        ' userString=DJM dataOffset=128' ||
                        ' scanlineOrder=INVERSE pixelOrder=REVERSE' ||
                        ' interleaving=BIL numberOfBands=1' ||
                        ' defaultChannelSelection=1');
    UPDATE stockphotos SET photo = Image WHERE photo_id = 1;
END;
/

setSource( ) Method

Format

setSource(source_type IN VARCHAR2,

source_location IN VARCHAR2,

source_name IN VARCHAR2);

Description

Sets or alters information about the external source of the image data.

Parameters

source_type

Sets or alters the srcType attribute of the image data source.

source_location

Sets or alters the srcLocation attribute of the image data source.

source_name

Sets or alters the srcName attribute of the image data source.

Pragmas

None.

Exceptions

None.

Usage Notes

Users can use this method to set the image data source to a new external file or URL.

Calling this method implicitly calls the setUpdateTime( ) method.

Examples

Set the source of the image data.

DECLARE
   Image ORDSYS.ORDVir;
   BEGIN
      SELECT photo INTO Image FROM stockphotos FOR UPDATE
         WHERE photo_id = 1;
   -- set source information for the image
      Image.setSource('file', 'ORDVIRDIR', 'jdoe.gif');
      UPDATE stockphotos SET photo = Image WHERE photo_id = 1;
   END;
/

setUpdateTime( ) Method

Format

setUpdateTime(current_time DATE);

Description

Sets the time when the image data was last updated.

Parameters

current_time

The updated time. Default is SYSDATE.

Pragmas

None.

Exceptions

None.

Usage Notes

Use this method whenever you modify the image data. The process( ), processCopy( ), and setProperties( ) methods all call this method and
setMimeType( ) implicitly.

Examples

Set the updated time of some image data.

DECLARE
   Image ORDSYS.ORDVir;
   BEGIN
      SELECT photo INTO Image FROM stockphotos FOR UPDATE
         WHERE photo_id = 1;
   -- set image update time
      Image.setUpdateTime(SYSDATE);
      UPDATE stockphotos SET photo = Image WHERE photo_id = 1;
   END;
/

4.5 Operators for Visual Information Retrieval

The Visual Information Retrieval operators are located in the ORDSYS schema.

Two operators are located in the ORDSYS.VIR package:

For ease of use, you can create a local synonym for the ORDSYS.ORDVIR_PKG package. Connect to your schema and enter the following command:

SQL> CREATE SYNONYM VIR FOR ORDSYS.ORDVIR_PKG; 

After creating the synonym, you can use it in calls to the operators: VIR.Analyze( ), VIR.Convert( ), and so forth. Note that you must have the default CREATE SYNONYM privilege.

Two additional operators are schema level operators and do not reside within the package. These operators use the domain index, if it exists.


Analyze( ) Operator

Format

Analyze(image IN OUT ORDVir);

Description

Analyzes an image, derives information relating to the visual attributes, creates the image signature, and stores it in the ORDVir object.

Parameters

image

The ORDVir object to be analyzed.

Pragmas

None.

Exceptions

None.

Usage Notes

The Analyze( ) operator creates the image signature (or feature vector), which is necessary for any content-based retrieval. Whenever you are working with a new or changed image, you should call Analyze( ) to generate a signature and then use the setProperties( ) method to set the other image characteristics.

During analysis, images are temporarily scaled to a common size such that the signatures are based on a common reference.

Example

Create the signatures for all images in the stockphotos table.

DECLARE
   temp_image   ORDSYS.ORDVir;
   temp_id      INTEGER;
   cursor c1 is select photo_id, photo from stockphotos for update;
BEGIN
   OPEN c1;
   LOOP
      fetch c1 into temp_id, temp_image;
      EXIT WHEN c1%NOTFOUND;
  
 -- Generate signature and set the properties for the image.
      ORDSYS.VIR.Analyze(temp_image); 
      temp_image.setProperties;
      UPDATE stockphotos SET photo = temp_image WHERE photo_id = temp_id;
   END LOOP;
   CLOSE c1;
END;


Convert( ) Operator

Format

Convert(signature IN OUT RAW, operations IN VARCHAR2)

RETURN BINARY_INTEGER;

Description

Converts the image signature to a format usable by the host machine.

Parameters

signature

The signature of the image, as created by the Analyze( ) operator. Data type is RAW(2000).

operations

The kind of processing done to the image signature. The following operation is available:

Operation Keyword  Description 

BYTEORDER 

Converts the signature to the natural byte order of the host machine.  

Pragmas

None.

Exceptions

None.

Usage Notes

When the operation is BYTEORDER, the signature is converted to the format of the host machine regardless of its initial state.

This procedure is useful if the database is stored on a remote system, but you want to do your processing locally. If your host machine is from Sun Microsystems, Inc., the Convert( ) operator sets the signature to the big endian byte order. On an Intel Corporation machine, the operator converts the signature to the little endian byte order. Note that the images themselves are platform-independent; only the signatures need to be converted.

Examples

Convert the signature of the image with photo_id=1 to the platform of the host system.

DECLARE 
  myimage ORDSYS.ORDVir; 
  convert_result BINARY_INTEGER; 
BEGIN 
  SELECT photo INTO myimage FROM stockphotos WHERE photo_id=1 FOR UPDATE;
  convert_result := ORDSYS.VIR.Convert(myimage.signature,'BYTEORDER'); 
  UPDATE stockphotos SET photo=myimage WHERE photo_id =1; 
END; 


VIRScore( ) Operator

Format

VIRScore(referencetoSimilar IN NUMBER);

Description

Compares the signatures of two images and returns a number representing the weighted sum of the distances for the visual attributes. VIRScore( ) is an ancillary operator, used only in conjunction with the primary operator, VIRSimilar( ).

Parameters

referencetoSimilar

The corresponding invocation of VIRSimilar. If there are multiple invocations of VIRSimilar in the same query, this parameter is used to maintain reference.
Data type is NUMBER.

Return Value

This function returns a FLOAT value between 0.0 and 100.0, where 0.0 is identical and 100.0 is completely different.

Pragmas

None.

Exceptions

None.

Usage Notes

Before the VIRScore( ) operator can be used, the image signatures must be created with the VIR.Analyze( ) operator. Also, if you want the comparison to use the domain index, the index of type ORDVIRIDX must have already been created. See Section 2.4 for information on creating and using the index, and see Section 3.8 for additional performance tips.

The VIRScore( ) operator can be useful when an application wants to make finer distinctions about matching than the simple Yes or No returned by
VIRSimilar( ). For example, using the number for weighted sum returned by VIRScore( ), the application might assign each image being compared to one of several categories, such as Definite Matches, Probable Matches, Possible Matches, and Nonmatches. The VIRScore( ) operator can also be useful if the application needs to perform special processing based on the degree of similarity between images.

The VIRScore( ) operator also works with old signatures stored using the deprecated ORDVirB and ORDVirF object types. However, Oracle Corporation recommends that you migrate to the new object type using the migrateFromORDVirF( ) and
migrateFromORDVirB( ) methods.

Examples

Find the weighted sum of the distances between a test image and the other images in the stockphotos table, using a threshold of 50 and the following weights for the visual attributes:

This example assumes that the signatures were already created using the Analyze( ) operator and they are stored in the database. Notice that both VIRScore( ) and VIRSimilar( ) are using 123 as the reference number in this example.

DECLARE
   img_score       NUMBER;
   i               INTEGER;
   query_signature RAW(2000);
   img             ORDSYS.ORDVir;

BEGIN
SELECT photo_id, ORDSYS.VIRScore(123), photo INTO i, img_score, img FROM stockphotos WHERE
     ORDSYS.VIRSimilar(img.signature, query_signature, 
               'globalcolor="0.2" localcolor="0.2" 
texture="0.1" structure="0.5"', 50, 123) = 1 END;

The following shows possible results from this example. The first image has the lowest score, and therefore is the best match of the test image. Changing the weights used in the scoring would lead to different results.

PHOTO_ID   SCORE 
---------- ------------
         2    3.79988   
         4    47.8139   
  2 rows selected.

VIRSimilar( ) Operator

Format

VIRSimilar(signature IN RAW,

querysignature IN RAW,

weightstring IN VARCHAR2,

threshold IN FLOAT

[ ,referencetoScore IN NUMBER] );

where weightstring is: 'globalcolor="val" localcolor="val" texture="val" structure="val"'

Description

Determines whether or not two images match. Specifically, the operator compares the signatures of two images, computes a weighted sum of the distance between the two images using user-supplied weight values for the visual attributes, compares the weighted sum with the threshold value, and returns the integer value 1 if the weighted sum is less than or equal to the threshold value. Otherwise, the operator returns 0.

Parameters

signature

The signature of the image to which you are comparing the query image. Data type is RAW(2000). To use the domain index for the comparison, this first parameter must be the signature column on which the domain index has been created. Otherwise, Oracle8i uses the non-indexed implementation of query evaluation.

querysignature

The signature of the query or test image. Data type is RAW(2000).

weightstring

A list of weights to apply to each visual attribute. Data type is VARCHAR2. The following attributes can be specified, with a value of 0.0 specifying no importance and a value of 1.0 specifying highest importance. You must specify a value greater than zero for at least one of the attributes.

Attribute  Description 

globalcolor 

The weight value (0.0 to 1.0) assigned to the global color visual attribute. Data type is number. Default is 0.0. 

localcolor 

The weight value (0.0 to 1.0) assigned to the local color visual attribute. Data type is number. Default is 0.0. 

texture 

The weight value (0.0 to 1.0) assigned to the texture visual attribute. Data type is number. Default is 0.0. 

structure 

The weight value (0.0 to 1.0) assigned to the structure visual attribute. Data type is number. Default is 0.0. 


Note:

When specifying parameter values that include floating-point numbers, you should use double quotation marks
(" ") around the value. If you do not, this may result in incorrect values being passed, and you will get incorrect results. 


threshold

The threshold value with which the weighted sum of the distances is to be compared. If the weighted sum is less than or equal to the threshold value, the images are considered to match. This range of this parameter is from 0.0 to 100.0.

referencetoScore

An optional parameter used when ancillary data (score of similarity) is required elsewhere in the query. Set this parameter to the same value here as used in the VIRScore( ) operator. Data type is NUMBER.

Return Value

Returns an integer value of 0 (not similar) or 1 (match).

Pragmas

None.

Exceptions

None.

Usage Notes

Before the VIRSimilar( ) operator can be used, the image signatures must be created with the Analyze( ) operator. Also, to use the domain index, the index of type ORDVIRIDX must have already been created. See Section 2.4 for information on creating and using the index and see Section 3.8 for additional performance tips.

The VIRSimilar( ) operator is useful when the application needs a simple Yes or No for whether or not two images match. The VIRScore( ) operator is useful when an application wants to make finer distinctions about matching or to perform special processing based on the degree of similarity between images.

The weights supplied for the four visual attributes are normalized prior to processing such that they add up to 100 percent. To avoid confusion and meaningless results, you should develop a habit of always using the same scale, whether 0 to 100 or 0.0 to 1.0.

You must specify at least one of the four image attributes in the weightstring.

The VIRSimilar( ) operator also works with old signatures stored using the deprecated ORDVirB and ORDVirF object types. However, Oracle Corporation recommends that you migrate to the new object type using the migrateFromORDVirF( ) and
migrateFromORDVirB( ) methods.

Examples

Using the VIR index, find all images similar to the query image using a threshold value of 25 and the following weights for the visual attributes:

This example assumes you already used the Analyze( ) operator to generate a signature for the query image. If an index exists on the signature column, it will be used automatically.

DECLARE
   t_img ORDSYS.ORDVIR;
   i     INTEGER;
   query_signature RAW(2000);
BEGIN
   SELECT photo_id, photo INTO i, t_img FROM stockphotos WHERE 
        ORDSYS.VIRSimilar(t_img.signature, query_signature, 
                 'globalcolor="20"  localcolor="20" 
texture="10" structure="50"', 25) = 1; END;

Go to previous page Go to next page
Oracle
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index