LBitmap::GWireGetMinPath

#include "ltwrappr.h" 

virtual L_INT LBitmap::GWireGetMinPath(hGWire, ptTarget, pOutPath, nOutLength)

GWIREHANDLE hGWire;

gwire handle

L_POINT ptTarget;

point structure that represent the end of minimal path

L_POINT** pOutPath;

pointer of pointer to L_POINT that represents the minimal path points

L_INT* nOutLength;

the length of the minimal path

Constructs a minimal path from the seed point to the target point and returns a pointer to L_POINT values that represents that path.

Parameter

Description

hGWire

Pointer to the Gwire handle.

ptTarget

Point structure that represent the end of minimal path.

pOutPath

Pointer of a pointer to L_POINT values that represents the points along the minimal path.

nOutLength

The length of the minimal path.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function is useful for extracting objects from an image. It works by constructing a minimal path between two input points (the seed point and the target point) that follows the edges of the image's objects. The minimal paths that are returned can be used to create a region covering the object of interest.

Call LBitmap::GWireInit and lbitmap::gwiresetseedpoint before calling this function.

Free the path generated by this function by calling the LBitmap::FreeGWirePath function.

If the image contains a region the region is ignored. The GWire algorithm works on the entire image.

Required DLLs and Libraries

LTDIS
LTFIL
LTIMGCOR

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:

LBitmap::LevelsetBitmapRgn, LBitmap::LambdaConnectedness, LBitmap::ShrinkWrapTool, LBitmap::WatershedBitmap, LBitmap::KMeansBitmapSegmentationLBitmap::GWireSetSeedPoint, LBitmap::FreeGWirePathLBitmap::GWireInit, Class Members

Topics: Raster Image Functions: Image Analysis
Processing an Image

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
L_VOID FreeGWireData(LBitmap LeadBitmap,L_INT SeedPointsCount, L_POINT* PathsBuf[], GWIREHANDLE* pHGWire); 
L_INT LBitmap__GWireExample() 
{ 
   L_INT nRet; 
   LBitmap LeadBitmap;   /* Bitmap handle to hold the loaded image. */ 
   /* Load the bitmap, keeping the bits per pixel of the file */ 
   nRet = LeadBitmap.Load(MAKE_IMAGE_PATH(TEXT("IMAGE3.dcm")), 0, ORDER_BGR); 
   if(nRet !=SUCCESS) 
      return nRet; 
   pBITMAPHANDLE pBitmapHandle =  LeadBitmap.GetHandle(); 
   GWIREHANDLE HGWire ; 
   L_INT       nExternalEnergy               = 90 ; 
   const L_INT SeedPointsCount               = 9 ; 
   L_POINT*    pOutPath[SeedPointsCount]     = {} ; 
   L_INT       pOutLength[SeedPointsCount]   = {} ; 
   L_POINT     SeedPoints[SeedPointsCount+1] ; 
   L_INT       length                        = 0 ; 
   nRet = LeadBitmap.GWireInit(&HGWire, nExternalEnergy); 
   if (nRet != SUCCESS) 
      return nRet ; 
   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 ; 
   SeedPoints[9].x = 200 ; SeedPoints[9].y = 163 ; 
   // Loop over the list of SeedPoints to get the minimum path between each set of two points. 
   // And add the minimum path between the two points to the AllPaths List. 
   for (int index = 0 ; index < SeedPointsCount ; index++ ) 
   { 
      // Set the seed point. 
      nRet = LeadBitmap.GWireSetSeedPoint(HGWire, SeedPoints[index]); 
      // Get the minimum path from the seed point to the target point. 
      if(nRet == SUCCESS) 
      { 
         nRet = LeadBitmap.GWireGetMinPath(HGWire, SeedPoints[index+1], &(pOutPath[index]), &(pOutLength[index])); 
         length += pOutLength[index] ; 
      } 
      if(nRet != SUCCESS) 
      { 
         FreeGWireData(LeadBitmap, SeedPointsCount, pOutPath, &HGWire); 
         if(pBitmapHandle->Flags.Allocated) 
            L_FreeBitmap(pBitmapHandle); 
         return nRet ; 
      } 
   } 
   L_POINT* pCombinedPaths = (L_POINT*) malloc((length)*sizeof(L_POINT)); 
   if(pCombinedPaths == NULL) 
   { 
      FreeGWireData(LeadBitmap,SeedPointsCount, pOutPath, &HGWire); 
      //free bitmap 
      if(pBitmapHandle->Flags.Allocated) 
         L_FreeBitmap(pBitmapHandle); 
      return ERROR_NO_MEMORY; 
   } 
   L_INT outIdx = 0 ; 
   for(L_INT index = 0 ; index < 9 ; index++ ) 
   { 
      memcpy(pCombinedPaths+outIdx, pOutPath[index], sizeof(L_POINT)*pOutLength[index]) ; 
      outIdx += pOutLength[index] ; 
   } 
   FreeGWireData(LeadBitmap, SeedPointsCount, pOutPath, &HGWire) ; 
   LBitmapRgn bitmapRgn; 
   bitmapRgn.SetBitmap(&LeadBitmap) ; 
   bitmapRgn.SetRgnPolygon(pCombinedPaths, length, L_POLY_WINDING); 
   free(pCombinedPaths) ; 
   if(nRet == SUCCESS) 
      nRet = LeadBitmap.Save (MAKE_IMAGE_PATH(TEXT("Result.BMP")), FILE_BMP, 24, 0, NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
   //free bitmap 
   if(pBitmapHandle->Flags.Allocated) 
      L_FreeBitmap(pBitmapHandle) ; 
   return nRet ; 
} 
L_VOID FreeGWireData(LBitmap LeadBitmap,L_INT SeedPointsCount, L_POINT* PathsBuf[], GWIREHANDLE* pHGWire) 
{ 
   for (int j = 0 ; j < SeedPointsCount ; j++) 
   { 
      LeadBitmap.FreeGWirePath(PathsBuf[j]); 
   } 
   LeadBitmap.DestroyGWireHandle(*pHGWire); 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C++ Class Library Help