#include "Ltimgcor.h"
L_LTIMGCOR_API L_INT L_GWireGetMinPath(hGWire, ptTarget, pOutPath, nOutLength)
Constructs a minimal path from the seed point to the target point and returns a pointer of L_POINT values that represents that path.
GWire handle.
Point structure that represents the end of minimal path.
Pointer of a pointer to L_POINT values that represent the points along the minimal path.
The length of the minimal path.
Value | Meaning |
---|---|
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
Win32, x64.
This example loads a bitmap and applies G-Wire segmentation.
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 ;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document