A graphic illustrator in the advertising agency is developing a new print advertisement for a client. The illustrator wants to use a particular shade of blue in the background of the advertisement, and wants to see if the color has been used before in printed advertisements created by the agency. To do that, the graphic illustrator runs an application that searches for images by content. The images are stored in a database table (see Figure 1). The application asks the user to supply a visual example, that is, an image that demonstrates the color of interest. The application then analyzes the color in the example and finds images whose color best matches the example.
The following figure shows a visual example and the retrieved images that most closely match its color.
Figure 4. Searching for images by content
![]() |
The following example shows some key elements of the application. Notice that the application uses a QBIC API named QbQueryCreate to create a QBIC query, QbQueryAddFeature and QbQuerySetFeatureData to add the color selection to the query, QbQuerySearch to issue the query, and QbQueryDelete to delete the query. The application also uses a graphical API, named DBiBrowse, to display the retrieved images.
Figure 5. An application that searches for images by content
#include <dmbqbqpi.h> #define MaxQueryReturns 10 static SQLHENV henv; static SQLHDBC hdbc; static SQLHSTMT hstmt; static SQLRETURN rc; void main(int argc, char* argv[]) { char line[4000]; char* handles[MaxQueryReturns]; QbQueryHandle qHandle=0; QbResult results[MaxQueryReturns]; SQLINTEGER count; SQLINTEGER resultType=qbiArray; SQlAllocEnv(&henv); SQLAllocConnect(henv, &hdbc); rc = SQLConnect(hdbc, (SQLCHAR*)"qtest", SQL_NTS, (SQLCHAR*)"", SQL_NTS, (SQLCHAR*)"", SQL_NTS); if (argc !=2) { printf("usage: query colorname\n"); exit(1); } QbImageSource is; is.type = qbiSource_AverageColor; /* run the get color subroutine */ getColor(argv[1], is.average.Color); QbQueryCreate(&qhandle); QbQueryAddFeature(qhandle, "QbColorFeatureClass"); QbQuerySetFeatureData(qhandle, "QbColorFeatureClass",&is); QbQuerySearch(qhandle, "ADS", "ADS_IMAGE", 10, 0, resultType &count, results); for (int j = 0; j <count; j++) { printf(j,":\n"); DBiBrowse("usr/local/bin/xv %s", MMDB_PLAY_HANDLE, handles[j], MMDB_PLAY_WAIT); } QbQueryDelete(qhandle); SQLDisconnect(hdbc); SQLFreeConnect(hdbc); SQLFreeEnv(henv); } |