L_CorrelationBitmap

#include "l_bitmap.h"

L_LTIMGCOR_API L_INT L_CorrelationBitmap(pBitmap, pCorBitmap, pPoints, uMaxPoints, puNumOfPoints, uXStep, uYStep, uThreshold, uFlags)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

pBITMAPHANDLE pCorBitmap;

/* pointer to the correlation bitmap handle */

POINT *pPoints;

/* pointer to an array of points */

L_UINT uMaxPoints;

/* array size */

L_UINT *puNumOfPoints;

/* pointer to the array size */

L_UINT uXStep;

/* size of the X step */

L_UINT uYStep;

/* size of the Y step */

L_UINT uThreshold;

/* threshold */

L_UINT32 uFlags;

/* flags */

This function compares pCorBitmap (or part of pCorBitmap) with all the areas of the same dimensions in pBitmap and finds those portions that match according to the measure of correlation.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the bitmap to be searched.

pCorBitmap

Pointer to the bitmap handle that references the bitmap for which to search.

pPoints

Pointer to an array of points. This array will be filled with the starting points for the correlated areas.

uMaxPoints

Size of the point array. This is also equal to the maximum number of regions in pBitmap that can be found to be correlated.

puNumOfPoints

Pointer to a variable to be updated with the number of areas in pBitmap actually found to be correlated to pCorBitmap. Its maximum value is uMaxPoints.

uXStep

Step size in the X direction (along image width), in pixels. For best results, use 1.

uYStep

Step size in the Y direction (along image height), in pixels. For best results, use 1.

uThreshold

Value that indicates the correlation threshold, which is a measure of association required to consider two areas to be correlated. If the correlation value between pCorBitmap and an area in pBitmap is less than the correlation threshold they are uncorrelated. Valid values range from 0 (zero resemblance) to 100 (perfect resemblance).

uFlags

Reserved for future use. Must be 0.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function compares pCorBitmap (or a part of pCorBitmap) with all the areas of the same dimensions in pBitmap and finds those areas that match according to the measure of correlation. Correlation is a measure of association (resemblance) between two images. It varies from 0 (zero resemblance) to 100 (perfect resemblance). This function updates the pPoints parameter with the point of origin for those areas of pBitmap where the resemblance with pCorBitmap (or part of pCorBitmap) is greater than the value of uThreshold. The pCorBitmap dimensions must be less than or equal to the pBitmap dimensions.

For example:

1.

Select a bitmap of the object for which you want to look. Put it in pCorBitmap

For example:

image\Correlation1.gif

2.

Select a bitmap that contains the object for which you are searching and put it in pBitmap

For example:

image\Correlation2.gif

3.

Call L_CorrelationBitmap.

4.

The function will update the pPoints array parameter with the point of origin (top-left) for each area of the bitmap pBitmap where the correlation with pCorBitmap is greater than the correlation threshold. The height and width of the rectangles are the same as for pCorBitmap.

5.

The result is:

image\Correlation3.gif

To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.

This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available in the Document and Medical Imaging toolkits.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

The sign flag in the BITMAPHANDLE structure must be the same for all images listed. That is, all images must be either signed or unsigned.

Required DLLs and Libraries

LTIMGEFX

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64.

See Also

Functions:

L_IntensityDetectBitmap, L_SpatialFilterBitmap, L_BinaryFilterBitmap, L_MaxFilterBitmap, L_MinFilterBitmap

Topics:

Processing an Image

 

Raster Image Functions: Comparing Images

 

Color Halftone and Halftone Images

 

Raster Image Functions: Processing an Image

Example

This example loads bitmaps, and applies the correlation filter

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName


#if defined (LEADTOOLS_V16_OR_LATER)
 L_INT CorrelationBitmapExample(L_VOID)
{
   L_INT nRet;
   BITMAPHANDLE LeadBitmap;
   BITMAPHANDLE CorBitmap;
   POINT    pPoints[10] = {0};
   L_UINT  uNumOfPoints;

   /* Load the bitmap, keeping the bits per pixel of the file */
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("IMAGE1.CMP")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet !=SUCCESS)
      return nRet;
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("IMAGE2.CMP")), &CorBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet !=SUCCESS)
      return nRet;

   /*Apply the correlation filter*/
   nRet = L_CorrelationBitmap(&LeadBitmap, &CorBitmap, pPoints, 10, &uNumOfPoints, 1, 2, 90, 0);
   if(nRet !=SUCCESS)
      return nRet;
   //free Bitmap
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL);
   if(nRet !=SUCCESS)
      return nRet;
   //free bitmap 
   if(LeadBitmap.Flags.Allocated)  
      L_FreeBitmap(&LeadBitmap);  
   if(CorBitmap.Flags.Allocated)  
      L_FreeBitmap(&CorBitmap);
   return SUCCESS;
}
#else
 L_INT CorrelationBitmapExample(L_VOID)
{
   L_INT nRet;
   BITMAPHANDLE LeadBitmap;
   BITMAPHANDLE CorBitmap;
   POINT    pPoints[10] = {0};
   L_UINT  uNumOfPoints;

   /* Load the bitmap, keeping the bits per pixel of the file */
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("IMAGE1.CMP")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet !=SUCCESS)
      return nRet;
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("IMAGE2.CMP")), &CorBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet !=SUCCESS)
      return nRet;

   /*Apply the correlation filter*/
   nRet = L_CorrelationBitmap(&LeadBitmap, &CorBitmap, pPoints, 10, &uNumOfPoints, 1, 2, 90);
   if(nRet !=SUCCESS)
      return nRet;
   //free Bitmap
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL);
   if(nRet !=SUCCESS)
      return nRet;
   //free bitmap 
   if(LeadBitmap.Flags.Allocated)  
      L_FreeBitmap(&LeadBitmap);  
   if(CorBitmap.Flags.Allocated)  
      L_FreeBitmap(&CorBitmap);
   return SUCCESS;
}
#endif // LEADTOOLS_V16_OR_LATER