Constructs a minimal path from the seed point to the target point and returns a pointer to L_POINT values that represents that path.
#include "ltwrappr.h"
virtual L_INT LBitmap::GWireGetMinPath(hGWire, ptTarget, pOutPath, nOutLength)
Pointer to the Gwire handle.
Point structure that represent the end of minimal path.
Pointer of a pointer to L_POINT values that represents 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 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.
Gwire Tool Function - Before
Gwire Tool Function - After
View additional platform support for this Gwire Tool function.
Win32, x64.
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 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