L_AlignImages

Summary

Aligns two images (the pRefBitmap and pTempBitmap images) based on the locations of the input points. The images are combined, creating the pOutBitmap image.

Syntax

#include "Ltimgcor.h"

L_LTIMGCOR_API L_INT L_AlignImages(pRefBitmap, pTempBitmap, pOutBitmap, RefPoints, TempPoints, PointsCount, nTransformationMethod)

Parameters

BITMAPHANDLE* pRefBitmap

Pointer to the bitmap handle that represents the reference bitmap.

BITMAPHANDLE* pTempBitmap

Pointer to the bitmap handle that represents the template bitmap to be mapped to the reference bitmap.

BITMAPHANDLE* pOutBitmap

Pointer of pointer to the bitmap handle that contains the result of the alignment.

L_POINT* RefPoints

Pointer to an L_POINT that contains the feature points in the reference image to be used for the alignment process.

L_POINT* TempPoints

Pointer to an L_POINT that contains the feature points in the template image to be used for the alignment process.

L_INT PointsCount

Number of alignment points.

L_UINT nTransformationMethod

Flag that determine which transformation method to use during alignment, If it is not known which method to use, use the IMAGE_REGISTRATION_UNKNOWN flag. The following values are possible:

Value Meaning
IMAGE_REGISTRATION_UNKNOWN Unknown transformation type. The transformation algorithm will be selected automatically.
IMAGE_REGISTRATION_XY Perform XY translation using one pair of corresponding points during registration.
IMAGE_REGISTRATION_RSXY Perform rotational, scaling and XY transformations using two pairs of corresponding points during registration.
IMAGE_REGISTRATION_AFFINE6 Perform rotational, scaling, shearing, and XY transformations using three pairs of corresponding points during registration.
IMAGE_REGISTRATION_AFFINE8 Perform perspective transformation using four pairs of corresponding points during registration.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

The two images should have the same depth (i.e. Bits Per Pixel). It is best to choose points that are far apart from each other.

The transformation performed depends upon the number of pairs of corresponding points given. As many as four pairs can be given.

This function supports 12- and 16-bit grayscale and 48- and 64-bit color images.

This function can only process entire images. It does not support regions.

This command supports signed/unsigned images.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

This example loads a bitmap and shows how to register it with a rotated version.

L_INT AlignImagesExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image. */ 
   pBITMAPHANDLE pLeadBitmap = &LeadBitmap; 
 
   /* Load the bitmap, keeping the bits per pixel of the file */ 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("cannon.jpg")), pLeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   // Rotate a copy the bitmap to be registered 
   BITMAPHANDLE TemplateImage; 
   pBITMAPHANDLE pTemplateImage = &TemplateImage; 
 
   nRet = L_CopyBitmap(pTemplateImage, pLeadBitmap, sizeof(BITMAPHANDLE)); 
   if (nRet != SUCCESS) 
   { 
      if (pLeadBitmap->Flags.Allocated) 
         L_FreeBitmap(pLeadBitmap); 
 
      return nRet; 
   } 
 
   nRet = L_RotateBitmap(pTemplateImage, 4500, ROTATE_BICUBIC, 0); 
   if (nRet != SUCCESS) 
   { 
      if (pLeadBitmap->Flags.Allocated) 
         L_FreeBitmap(pLeadBitmap); 
 
      if (pTemplateImage->Flags.Allocated) 
         L_FreeBitmap(pTemplateImage); 
 
      return nRet; 
   } 
 
   //Get feature points from the two images that correspond to each other. 
   L_POINT RefPoints[2]; 
   L_POINT TempPoints[2]; 
 
   RefPoints[0].x = 173; RefPoints[0].y = 102; 
   RefPoints[1].x = 216; RefPoints[1].y = 259; 
 
   TempPoints[0].x = 239; TempPoints[0].y = 66; 
   TempPoints[1].x = 158; TempPoints[1].y = 207; 
 
   BITMAPHANDLE outBitmap; 
 
   nRet = L_AlignImages(pLeadBitmap, 
      pTemplateImage, 
      &outBitmap, 
      RefPoints, 
      TempPoints, 
      2, 
      IMAGE_REGISTRATION_UNKNOWN); 
 
   if (nRet == SUCCESS) 
      nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &outBitmap, FILE_BMP, 24, 0, NULL); 
 
   //free bitmaps 
   if (pLeadBitmap->Flags.Allocated) 
      L_FreeBitmap(pLeadBitmap); 
 
   if (pTemplateImage->Flags.Allocated) 
      L_FreeBitmap(pTemplateImage); 
 
   if (outBitmap.Flags.Allocated) 
      L_FreeBitmap(&outBitmap); 
 
   return nRet; 
} 

Help Version 22.0.2023.7.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.