L_GWireInit

Summary

Initializes the Gwire handle to be used in finding the minimal path.

Syntax

#include "Ltimgcor.h"

L_LTIMGCOR_API L_INT L_GWireInit(pBitmap, pHGWire, nExternalEnergy)

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle.

GWIREHANDLE *pHGWire

Pointer to the Gwire handle.

L_INT nExternalEnergy

Integer value that represents the value of the external energy used in constructing the minimum paths in the image. Possible values range from 0 to 100. The default value is 90.

Returns

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

Comments

GWire is an adaptation of the livewire technique for segmenting an image. Whereas livewire techniques use external energy (only) to find the boundary, GWire uses both external energy as well as internal energy, making it less sensitive to noise. The nExternalEnergy parameter balances the minimal path length with the minimal path weight.

This function initializes the GWire engine and should be called before using the L_GWireSetSeedPoint or L_GWireGetMinPath function. Free the handle generated by calling the L_DestroyGWireHandle function.

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

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

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

This example loads a bitmap and applies GWire segmentation filter.

L_INT GWireFilterBitmapExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image. */ 
 
   /* Load the bitmap, keeping the bits per pixel of the file */ 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("DICOM\\IMAGE3.dcm")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   GWIREHANDLE gwire; 
 
   nRet = L_GWireInit(&LeadBitmap, &gwire, 90); 
   if (nRet != SUCCESS) 
   { 
      L_DestroyGWireHandle(gwire); 
 
      if (LeadBitmap.Flags.Allocated) 
         L_FreeBitmap(&LeadBitmap); 
 
      return nRet; 
   } 
 
   POINT** ppGWirePaths; 
   L_INT* pGWireLengths; 
   ppGWirePaths = (POINT**)malloc(10 * sizeof(POINT*)); 
   pGWireLengths = (L_INT*)malloc(10 * sizeof(L_INT)); 
   if (ppGWirePaths == NULL || pGWireLengths == NULL) 
   { 
      if (ppGWirePaths == NULL) free(ppGWirePaths); 
      if (pGWireLengths == NULL) free(pGWireLengths); 
 
      if (LeadBitmap.Flags.Allocated) 
         L_FreeBitmap(&LeadBitmap); 
 
      L_DestroyGWireHandle(gwire); 
 
      return ERROR_NO_MEMORY; 
   } 
 
   // Get the boundaries of the object 
   POINT SeedPoints[9]; 
   SeedPoints[0].x = 200; SeedPoints[0].y = 163; 
   SeedPoints[1].x = 245; SeedPoints[1].y = 195; 
   SeedPoints[2].x = 289; SeedPoints[2].y = 163; 
   SeedPoints[3].x = 282; SeedPoints[3].y = 188; 
   SeedPoints[4].x = 304; SeedPoints[4].y = 314; 
   SeedPoints[5].x = 247; SeedPoints[5].y = 271; 
   SeedPoints[6].x = 201; SeedPoints[6].y = 315; 
   SeedPoints[7].x = 228; SeedPoints[7].y = 199; 
   SeedPoints[8].x = 199; SeedPoints[8].y = 175; 
 
   L_INT pointIdx = 0; 
 
   // Loop over the list of SeedPoints to get the minimum path between each set of two points. 
   for (int index = 0; index < 4; index++) 
   { 
      // Set the seed point. 
      L_GWireSetSeedPoint(gwire, SeedPoints[pointIdx]); 
 
      pointIdx++; 
 
      // Get the minimum path from the seed point to the target point. 
      L_GWireGetMinPath(gwire, SeedPoints[pointIdx], &ppGWirePaths[index], &pGWireLengths[index]); 
   } 
 
   L_INT PointsSum = 0; 
   for (L_INT i = 0; i < pointIdx; i++) 
   { 
      PointsSum += pGWireLengths[i]; 
   } 
 
   // have all paths in one buffer. 
   POINT* pFinalPath = (POINT*)malloc(PointsSum * sizeof(POINT)); 
   L_INT PointsCount = 0; 
   for (L_INT i = 0; i < pointIdx; i++) 
   { 
      memcpy(&(pFinalPath[PointsCount]), ppGWirePaths[i], pGWireLengths[i] * sizeof(POINT)); 
      L_FreeGWirePath(ppGWirePaths[i]); 
      PointsCount += pGWireLengths[i]; 
   } 
 
   L_DestroyGWireHandle(gwire); 
   free(ppGWirePaths); 
   free(pGWireLengths); 
 
   // Use the minimum path around the object and convert it to a region. 
   L_SetBitmapRgnPolygon(&LeadBitmap, NULL, pFinalPath, PointsSum, L_POLY_ALTERNATE, L_RGN_SET); 
 
   return SUCCESS; 
} 

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.