L_GetTransformationParameters

#include "l_bitmap.h"

L_LTIMGCOR_API L_INT L_GetTransformationParameters (pBitmap, pRefPoints, pTrnsPoints, pnXTranslation, pnYTranslation, pnAngle, puXScale, puYScale, uFlags)

Computes the rotation angle, XY scaling, and XY translation of the transformed bitmap with comparison to the reference bitmap. These are the transformations that would have to be performed to the reference bitmap to have it match the current bitmap.

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle referencing the transformed bitmap.

POINT *pRefPoints

Pointer to an array of reference points. These points represent the center of mass points for the registration in the reference bitmap. You have to provide this information.

POINT *pTrnsPoints

Pointer to an array of transformed points. These points are the center of mass points in pBitmap. You have to provide this information.

L_INT *pnXTranslation

Pointer to a variable to be updated by the bitmap x-translation, in hundredths of pixels.

L_INT *pnYTranslation

Pointer to a variable to be updated by the bitmap y-translation, in hundredths of pixels.

L_INT *pnAngle

Pointer to a variable to be updated with the bitmap rotation angle, in hundredths of degrees.

L_UINT *puXScale

Pointer to a variable to be updated with the bitmap x-scaling (resizing), in percent.

L_UINT *puYScale

Pointer to a variable to be updated with the bitmap y-scaling (resizing), in percent.

L_UINT32 uFlags

Reserved for future use. Must be 0.

Returns

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

Comments

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

This function detects transformation parameters of the transformed bitmap by comparing it with the reference bitmap. The number of reference and detected points must be three.

Use L_GetMarksCenterMassBitmap to fill the pRefPoints array with the points representing the center of masses for each of the reference marks from the reference bitmap.

Fill the pTrnsPoints array by peforming the following steps:

Use L_SearchRegMarksBitmap to find the new positions for the reference marks

Using L_GetMarksCenterMassBitmap to fill the pTrnsPoint array with points representing the center of masses for each of the transformed reference marks.

The values pnXTranslation, pnYTranslation, pnAngle, puXScale and puYScale are internally divided by 100. For example, a pnAngle of 500 would mean to rotate the bitmap 5 degrees clockwise.

The results of this function must be sent without any modification to the L_ApplyTransformationParameters function in order to correct the image.

If you want to correct the image yourself, you have to perform the inverse operations in this order:

  1. Shift the image by (-pXTranslation / 100, -pYTranslation / 100) using L_CombineBitmap.
  2. Rotate without resizing by (*pnAngle).
  3. Resize using scaling factors of (100 / *puXScale, 100 / *puYScale) using L_SizeBitmap or L_ResizeBitmap.

This function does not use L_SetStatusCallback.

If you simply want to automatically straighten a bitmap, use the L_DeskewBitmap function.

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.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

L_INT GetTransformationParametersExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;   // Bitmap handle for the image  
   L_INT nAngle;  
   L_UINT  uXScale, uYScale ; 
   L_INT   nXTranslation,nYTranslation;  
   SEARCHMARKS aSearchMarks[3];  
   POINT  aMarkPoints[3];  
   POINT  aMarkCMPoints[3];  
   POINT aRefPoints[3];  
   POINT CenterPt;  
  
   // Load a bitmap at its own bits per pixel  
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("RGSRef.cmp")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);  
  
   if(nRet !=SUCCESS) 
      return nRet; 
  
   // bend the image around it is center  
   CenterPt.x  =  LeadBitmap.Width/2;  
   CenterPt.y  =  LeadBitmap.Height/2;  
  
   /* Get aRefPoints from pre-calculated saved values.*/ 
   aRefPoints[0].x = 80600;  
   aRefPoints[0].y = 11400;  
   aRefPoints[1].x = 78700;  
   aRefPoints[1].y = 116100;  
   aRefPoints[2].x = 13600;  
   aRefPoints[2].y = 115500;  
  
   /*Get registration marks CM*/ 
  
   aSearchMarks[0].uStructSize = sizeof(SEARCHMARKS); 
   aSearchMarks[0].uType = RGS_T;  
   aSearchMarks[0].uMinScale = 90;  
   aSearchMarks[0].uMaxScale = 110;  
   aSearchMarks[0].uWidth = 31;  
   aSearchMarks[0].uHeight = 29;  
   SetRect(&aSearchMarks[0].rcRect, 700,80,900,150);  
   aSearchMarks[0].uSearchMarkCount = 1;  
   aSearchMarks[0].pMarkDetectedPoints = (POINT  *) malloc(aSearchMarks[0].uSearchMarkCount * sizeof(POINT));  
  
   aSearchMarks[1].uStructSize = sizeof(SEARCHMARKS); 
   aSearchMarks[1].uType = RGS_T;  
   aSearchMarks[1].uMinScale = 90;  
   aSearchMarks[1].uMaxScale = 110;  
   aSearchMarks[1].uWidth = 31;  
   aSearchMarks[1].uHeight = 29;  
   SetRect(&aSearchMarks[1].rcRect,700,900,900,1250);  
   aSearchMarks[1].uSearchMarkCount = 1;  
   aSearchMarks[1].pMarkDetectedPoints = (POINT *) malloc(aSearchMarks[1].uSearchMarkCount * sizeof(POINT));  
  
   aSearchMarks[2].uStructSize = sizeof(SEARCHMARKS); 
   aSearchMarks[2].uType = RGS_T;  
   aSearchMarks[2].uMinScale = 90;  
   aSearchMarks[2].uMaxScale = 110;  
   aSearchMarks[2].uWidth = 31;  
   aSearchMarks[2].uHeight = 29;  
   SetRect(&aSearchMarks[2].rcRect,100,1100,200,1250);  
   aSearchMarks[2].uSearchMarkCount = 1;  
   aSearchMarks[2].pMarkDetectedPoints = (POINT  *)malloc(aSearchMarks[2].uSearchMarkCount * sizeof(POINT));  
  
   L_FreeBitmap(&LeadBitmap); 
 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("RGSTest.cmp")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);  
   if(nRet !=SUCCESS) 
      return nRet; 
  
  
   nRet = L_SearchRegMarksBitmap (&LeadBitmap,aSearchMarks,3, 0);  
   if(nRet !=SUCCESS) 
      return nRet; 
  
   aMarkPoints[0]= *aSearchMarks[0].pMarkDetectedPoints;  
   aMarkPoints[1]= *aSearchMarks[1].pMarkDetectedPoints;  
   aMarkPoints[2]= *aSearchMarks[2].pMarkDetectedPoints;  
  
   free(aSearchMarks[0].pMarkDetectedPoints);  
   free(aSearchMarks[1].pMarkDetectedPoints);  
   free(aSearchMarks[2].pMarkDetectedPoints);  
  
   nRet = L_GetMarksCenterMassBitmap (&LeadBitmap, aMarkPoints, aMarkCMPoints, 3, 0);  
   if(nRet !=SUCCESS) 
      return nRet; 
  
  
   nRet = L_GetTransformationParameters (&LeadBitmap, aRefPoints, aMarkCMPoints, &nXTranslation, &nYTranslation, &nAngle, &uXScale, &uYScale, 0);  
   if(nRet !=SUCCESS) 
      return nRet; 
  
  
   nRet = L_ApplyTransformationParameters (&LeadBitmap, nXTranslation, nYTranslation,nAngle,  uXScale, uYScale, RGS_SIZE_BICUBIC);  
   if(nRet !=SUCCESS) 
      return nRet; 
   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);   
   return SUCCESS; 
} 
Help Version 21.0.2023.2.15
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.