#include "Ltimgcor.h"
L_LTIMGCOR_API L_INT L_GWireGetMinPath(hGWire, ptTarget, pOutPath, nOutLength)
GWIREHANDLE hGWire; |
gwire handle |
L_POINT ptTarget; |
point structure that represents the end of minimal path |
L_POINT** pOutPath; |
pointer of a pointer to L_POINT values that represents the points along the minimal paths |
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 of L_POINT values that represents that path.
Parameter |
Description |
hGWire |
GWire handle. |
ptTarget |
Point structure that represents the end of minimal path. |
pOutPath |
Pointer of a pointer to L_POINT values that represent the points along the minimal path. |
nOutLength |
The length of the minimal path. |
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
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 L_GWireInit and L_GWireSetSeedPoint before calling this function.
Free the path generated by this function by calling the L_FreeGWirePath function.
If the image contains a region the region is ignored. The GWire algorithm works on the entire image.
Required DLLs and Libraries
For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
Win32, x64.
See Also
Functions: |
L_GWireInit, L_GWireSetSeedPoint, L_FreeGWirePath, L_DestroyGWireHandle |
Topics: |
Raster Image Functions: Image Analysis |
|
Processing an Image |
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
L_VOID FreeGWireData(L_INT SeedPointsCount, L_POINT* PathsBuf[], GWIREHANDLE* pHGWire)
{
for (int j = 0 ; j < SeedPointsCount ; j++)
{
L_FreeGWirePath(PathsBuf[j]);
}
L_DestroyGWireHandle(*pHGWire);
}
L_INT GWireExample(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("IMAGE3.dcm")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
if(nRet != SUCCESS)
return nRet ;
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 = L_GWireInit(&LeadBitmap, &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 = L_GWireSetSeedPoint(HGWire, SeedPoints[index]) ;
// Get the minimum path from the seed point to the target point.
if(nRet == SUCCESS)
{
nRet = L_GWireGetMinPath(HGWire, SeedPoints[index+1], &(pOutPath[index]), &(pOutLength[index])) ;
length += pOutLength[index] ;
}
if(nRet != SUCCESS)
{
FreeGWireData(SeedPointsCount, pOutPath, &HGWire);
if(LeadBitmap.Flags.Allocated)
L_FreeBitmap(&LeadBitmap);
return nRet ;
}
}
L_POINT* pCombinedPaths = (L_POINT*) malloc((length)*sizeof(L_POINT));
if(pCombinedPaths == NULL)
{
FreeGWireData(SeedPointsCount, pOutPath, &HGWire);
if(LeadBitmap.Flags.Allocated)
L_FreeBitmap(&LeadBitmap);
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(SeedPointsCount, pOutPath, &HGWire) ;
nRet = L_SetBitmapRgnPolygon(&LeadBitmap, NULL, pCombinedPaths, length, L_POLY_WINDING, L_RGN_SET);
free(pCombinedPaths) ;
if(nRet == SUCCESS)
nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL) ;
//free bitmap
if(LeadBitmap.Flags.Allocated)
L_FreeBitmap(&LeadBitmap) ;
return nRet ;
}
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET