Oracle8i Visual Information Retrieval User's Guide and Reference Release 8.1.5 A67293-01 |
|
A sample program is included with Visual Information Retrieval to demonstrate how to load two images into the database, generate their signatures, and then compare their signatures using a weighted similarity function.
This program uses two data files, virdemo1.dat and virdemo2.dat, as its input. No other input or parameters are required.
The following assumptions are made:
There are two ways to run the sample program: using the included sample images, or using your own images.
Example B-1 runs the sample program using the included image files. The images are compared using equal attribute weights:
% virdemo Image 1 and 2 have a similarity score of 0.0
Example B-2 shows how to specify your own images on the command line. The images must reside in the <ORACLE_HOME>/ord/vir/demo directory.
% virdemo <image1> <image2> <global_color> <local_color> <texture> <structure>
All six parameters: the 2 file names and 4 attribute weights (ranging from 0.0 to 1.0) must be specified in this sample program. Note that when using the VIRScore( ) operator in your own applications, it is only necessary to provide at least one attribute weight.
Several other sample image files have been provided in the VIRDEMODIR directory to demonstrate the effects of emphasizing the different visual attributes. You can use an image viewer (such as xv) to display the images, and then compare them using the sample program, experimenting with different weights. Figure B-1 shows the sample images.
The relative distance between the images being compared is called the score and is output during the execution of the sample program. A lower score indicates a closer match. A score of zero would indicate a perfect match.
A score is valid only for a given set of weights for the four visual attributes. If you change the weights, the results will change. For example, consider a comparison of national flags. The flag of Cote d'Ivoire (the Ivory Coast) is composed of three equal vertical color stripes: orange, white, and green. The flag of Ireland is composed of three vertical stripes in the reverse order: green, white, and orange. A comparison of flag images based on global color or structure would consider these two flags identical. However, a comparison emphasizing local color would return a much larger distance between the two images, indicating a poor match1.
The complete C language source code for the sample application is available in the
<ORACLE_HOME>/ord/vir/demo directory after installing Visual Information Retrieval. Note that the file specification may differ on your platform.
A small section of the program related to comparing images has been included here.
#ifdef RCSID static char *RCSid = "$Header: virdemo.c 18-nov-98.08:02:49 dmullen Exp $ "; #endif /* RCSID */ /* Copyright (c) Oracle Corporation 1997, 1998. All Rights Reserved. */ /* NAME virdemo.c - out-of-the-box demo using Oracle8i Visual Information Retrieval . . . /* * -------------------------------------------------------------------- * test_1_vir = Analyze the contents of the BLOB and BFILE and return the * score based on the weights assigned to the different features * ---------------------------------------------------------------------- */ sb4 test_1_vir(char *g_c, char * l_c, char * txtr, char * stre) { float w_sum = -1.999; /* dummy value */ text *sqlstmt = (text *) "DECLARE \ A ORDSYS.ORDVir; \ B ORDSYS.ORDVir; \ a_data BFILE; \ b_data BLOB; \ a_sig RAW(2000);\ b_sig RAW(2000);\ BEGIN \ SELECT FILEIMAGE INTO A FROM VIRDEMOTAB WHERE C1=1 FOR UPDATE;\ SELECT BLOBIMAGE INTO B FROM VIRDEMOTAB WHERE C1=2 FOR UPDATE;\ a_data := A.getBfile();\ b_data := B.getContent();\ ORDSYS.VIR.Analyze(a_data, a_sig);\ ORDSYS.VIR.Analyze(b_data, b_sig);\ :weighted_sum := ORDSYS.VIR.score(a_sig, b_sig, 'globalcolor='|| :g_color || ', localcolor= '|| :l_col or || ', texture=' || :texture || ', structure=' || :strct);\ END;";
1
In the case of using Visual Information Retrieval for flag recognition, you would need to know which direction the flag was facing in the test images.