ImageGear for C and C++ on Linux v18.8 - Updated
Image Analysis
User Guide > How to Work with... > Image Processing and Cleanup > Image Analysis

This section describes the following:

Histogram

ImageGear provides a histogram-generating function (and a related function to clear histogram bins) to assist you in image analysis. For an 8-bit image, whether 8i or 8-bit gray level, these functions can be called as follows:

 
Copy Code
HIGEAR hIGear; /* HIGEAR handle of image */
DWORD dwHistoBins[256]; /* Array of bins for counting */IG_IP_histo_clear( &dwHistoBins, 256 ); /* Clear the bins */IG_IP_histo_tabulate (hIGear, &dwHistoBins, 256, NULL, 1, 0 );
/* Tabulate: */

In the above call, 256 DWORD bins are provided (one for each possible pixel value that can occur). The function will examine each pixel in the image bitmap, and will increment the bin corresponding to that value; that is, the bin dwHistoBins[pixel value] will be incremented. Upon return, you will have a count of the number of occurrences of each pixel value.

The fourth argument in the above call lets you specify the address of a rectangular region if you want to restrict the tabulating to include only a portion of the image. When NULL, the whole image is included in the tabulation.

The fifth argument above can be set higher than 1 if you want to increase the speed of the tabulation for a large image. 1 means that every raster line of pixels will be included in the tabulation. A higher value would result in raster lines being skipped.

The final argument in a call to IG_IP_histo_tabulate() is relevant for 24-bit images only. Its use is shown in the following example:

 
Copy Code
HIGEAR hIGear; /* Handle of a 24-bit image */
DWORD dwHistoBins[256]; /* Array of bins for counting */
IG_IP_histo_clear ( &dwHistoBins, 256 );/* Clear the bins */
IG_IP_histo_tabulate (hIGear, &dwHistoBins, 256, NULL, 1, 
IG_COLOR_COMP_R ); /* Tabulate:   */

For 24-bit images, only 1 color channel is tabulated by a given call. That is, only 1 byte of each 3-byte pixel is examined. The final argument tells which byte (Blue, Green, or Red) should be tabulated.

You can also call IG_IP_histo_tabulate() for 1-bit and 4-bit images. In these cases, the number of DWORD histogram bins you need would be 2 and 16, respectively. In any event, always remember to call IG_IP_histo_clear() before calling IG_IP_histo_tabulate(), unless it is your intention to accumulate the count into the existing contents of your bins.

Color Counting

The IG_IP_color_count_get() function counts the number of different colors in the specified rectangle of an image.